Either the cue ball can touch ANY rail, or the eight would have to touch a DIFFERENT rail than it was frozen to. I'm not sure about the eight coming off the rail and then somehow making contact with the same rail. I guess it would be a good hit but not sure the rule book covers that scenario.
If an object ball is frozen to a rail, that rail is "out of play" for that object ball insofar as having that object ball strike a rail in order to have a legal shot. I does not matter if it comes off the rail and then hits it again. That OB must hit a different rail,
UNLESS it leaves that cushion and contacts another ball before hitting that cushion again.
Here is the applicable World Standardized Rule (Bold type added for emphasis):
3.38 OBJECT BALL FROZEN TO CUSHION OR CUE BALL
This rule applies to any shot where the cue ball’s first contact with a ball is with one that is frozen to a cushion or to the cue ball itself. After the cue ball makes contact with the frozen object ball, the shot must result in either:
(a) A ball being pocketed, or;
(b) The cue ball contacting a cushion, or;
(c)
The frozen ball being caused to contact a cushion attached to a separate rail, or;
(d) Another object ball being caused to contact a cushion with which it was not already in contact. Failure to satisfy one of those four requirements is a foul. (Note: 14.1 and other games specify additional requirements and applications of this rule; see specific game rules.)
A ball which is touching a cushion at the start of a shot and then is forced into a cushion attached to the same rail is not considered to have been driven to that cushion unless it leaves the cushion, contacts another ball, and then contacts the cushion again. An object ball is not considered frozen to a cushion unless it is examined and announced as such by either the referee or one of the players prior to that object ball being involved in a shot.
BTW, "contacts another ball" does not mean the cue ball. For instance, if you hit the cue ball into a double kiss with the 8 frozen to a rail, the 8 is not deemed to have left that rail. In fact, it probably didn't.