`On Mon, Aug 19, 2002 at 01:43:59AM -0400, Theodore Ts'o wrote:> On Sat, Aug 17, 2002 at 09:15:22PM -0500, Oliver Xymoron wrote:> > > > Non-Uniform Distribution Of Timing> > > >  Unfortunately, our sample source is far from uniform. For starters, each> >  interrupt has a finite time associated with it - the interrupt latency.> >  Back to back interrupts will result in samples that are periodically> >  spaced by a fixed interval.> > This is true.  But that's also why /dev/random measures not just the> first order delta, but the second and third order delta's as well, and> takes the minimum of the three delta's, capped by 12 bits, as the> entropy estimate.  So for example, if the interrupts are happening as> fast as possible (back to back) and there is merely the fixed interval> caused by the interrupt latency, then delta_1 will be the interrupt> latency, but delta_2 will be zero!  > > The rest of your analysis also ignores the fact that the current> /dev/random code uses the second and third order delta's (think of> them as second and third order deritives, except that we're in the> discrete rather than continous domain).No, I just chopped that part out of my analysis as it was alreadygetting rather lengthy. I concluded that it was easy to spoof thedeltas with untrusted sources if we weren't keeping track of at leastone global piece of information (I chose context switches) and thatthere wasn't a good physical interpretation of the third orderdelta. Neither of them protect from the latency-watching attack. I'vekept the first and second order deltas.> >  Assuming the interrupt actually has a nice gamma-like distribution> >  (which is unlikely in practice), then this is indeed true. The> >  trouble is that Linux assumes that if a delta is 13 bits, it contains> >  12 bits of actual entropy. A moment of thought will reveal that> >  binary numbers of the form 1xxxx can contain at most 4 bits of> >  entropy - it's a tautology that all binary numbers start with 1 when> >  you take off the leading zeros. This is actually a degenerate case of> >  Benford's Law (http://mathworld.wolfram.com/BenfordsLaw.html), which> >  governs the distribution of leading digits in scale invariant> >  distributions.> > > >  What we're concerned with is the entropy contained in digits> >  following the leading 1, which we can derive with a simple extension> >  of Benford's Law (and some Python):> > I'm not a statistician, and my last probability class was over 15> years ago, but I don't buy your extension of Benford's law.  Sure, if> we take street addresses numbering from 1 to 10000, the probability> that the leading digit will be 1 will be roughly 30%.  But the> distribution of the low two digits will be quite evenly distributed.> Put another way, by picking a house at random, and looking at the low> two digits, and can very fairly choose a number between 0 and 99.  That's correct, and that's what's being calculated. The example Pythoncode calculates the Benford distribution not in base 2, but in base2^bits. Then it uses the Shannon entropy definition to calculate theoverall entropy of that distribution. For a 12 bit number, we've gotabout 7 bits of entropy, most of it concentrated in the LSBs.> > Interrupt Timing Independence> > > >  Linux entropy estimate also wrongly assumes independence of different> >  interrupt sources. While SMP complicates the matter, this is> >  generally not the case. Low-priority interrupts must wait on high> >  priority ones and back to back interrupts on shared lines will> >  serialize themselves ABABABAB. Further system-wide CLI, cache flushes> >  and the like will skew -all- the timings and cause them to bunch up> >  in predictable fashion.> > > >  Furthermore, all this is observable from userspace in the same way> >  that worst-case latency is measured. > > > >  To protect against back to back measurements and userspace> >  observation, we insist that at least one context switch has occurred> >  since we last sampled before we trust a sample.> > First of all, the second order delta already protects against> back-to-back measurements.  Only from the same source. Imagine the case of sending a series ofback to back network interrupts that hold off a pending keyboard ordisk interrupt to a predictable window. Sorry, another long bit I snippedfrom my analysis.> Secondly, what is observable from userpsace is time which is not spent> in a particular process.  But whether that time was spent in the> system or in another process is not at all obvious, and it's also not> obvious whether that time is spent handling interrupts or processing> bottom half tasks (i.e., processing network packets, et. al).> Moreover, it is not observable to the user process when multiple> interrupts might be happening in this whole mess.But a userspace process can see that it's on an idle system with onlyeg timing interrupts happening. See the code that's used to measureworst-case latency for the lowlat and preempt patches. This same codecould easily be modified to record time stamps for non-timerinterrupts, and with respectable accuracy.Again, I keep the first and second order deltas of your approach andwatch context switching as an additional protection.> That being said, global CLI's are a problem in that it does mean that> multiple interrupts could be serviced at the same time, and while the> outside adversary won't know exactly when a global CLI/STI might have> happened, it does reduce the quality of the randomness.  The solution> to this though is to avoid global CLI's, not to throw away randomness> samples until after a context switch.  The context switch protection fires rarely (1-2%) and I'm still mixingsaid data into the pool.> > Questionable Sources and Time Scales> > > >  Due to the vagarities of computer architecture, things like keyboard> >  and mouse interrupts occur on their respective scanning or serial> >  clock edges, and are clocked relatively slowly. Worse, devices like> >  USB keyboards, mice, and disks tend to share interrupts and probably> >  line up on USB clock boundaries. Even PCI interrupts have a> >  granularity on the order of 33MHz (or worse, depending on the> >  particular adapter), which when timed by a fast processor's 2GHz> >  clock, make the low six bits of timing measurement predictable.> > We are not mixing in solely the low order bits of the timing> measurement; we're mixing in the entire timestamp.  So the fact that> the low-order bits of the timing measurement might be predictable> isn't necessarily a problem.  > > We are looking at the low 12 bits of the first, second, and third> order deltas when estimating the entropy.  So predictibility in the> low six bits of the timing measurement will tend to drag the entropy> estiamte down, not up.On a gigahertz processor, n order deltas on the order of a millisecondall show up as > 12 bits of accuracy. We're sampling a source that weknow to be aligned to a fixed multiple of the processor clock onmodern machines, therefore we can expect very little randomness in theLSBs. Even if our peripheral clocks are not generated from the sameclock source, we can't count on the LSBs being chaotic - clocks tendto be extremely stable and clock drift over time scales of 1GHz/2^12are going to be very small indeed.> >  And as far as I can find, no one's tried to make a good model or> >  estimate of actual keyboard or mouse entropy. > > Since a human is involved, and we're measuring to a fairly high level> of accuracy, I'm not particularly worried.Me neither, really. I would be worried if we tried to estimate entropyin position or keystroke data, but we don't.> >  Randomness caused by> >  disk drive platter turbulence has actually been measured and is on> >  the order of 100bits/minute and is well correlated on timescales of> >  seconds - we're likely way overestimating it. > > This has worried me.  The Davis paper was done a long time ago and I> suspect the turblence values has gone down over time, not up.  But> let's be clear what the problem is.  If the adversary knows the exact> stream of requests sent to a disk, it can probably model the time> necesasry to service those requests very accurately --- possibly> missing much less than the 100 bits/minute guestimated by the Davis> pater, given modern disk drives. > > So when we measure the disk drive completion interrupts, what we are> really measuring is the uncertainity to the attacker exactly *when*> those disk drive requests were made, and what order of disk drive> requests were sent to it.> > Can the adversary control this, or know this?  Sometimes, to a certain> extent.  But remember, we're using a very high resolution timer, and> while the adversary might not the rough time to a few milliseconds> when a request might be issued, it would be much harder for the> adversary to know at what exact time stamp clock value was at a> particular event.I think the adversary can do much better than that, especially giventhings like sendfile() and zerocopy networking that go to lengths tomake the latency as low as possible. Again, we don't have to guess tothe resolution of the processor clock, but to the bus clock (3 ordersof magnitude slower) or to the likely even slower microcontroller onthe peripheral. To the best of my knowledge, servo control loops fordrives are _not_ run in MHz. So the question becomes, is gigabitnetwork latency more predictable than the drive servo loop? I wouldn'tbet on the drive..> > Trusting Predictable or Measurable Sources> > > >  What entropy can be measured from disk timings are very often leaked> >  by immediately relaying data to web, shell, or X clients.  Further,> >  patterns of drive head movement can be remotely controlled by clients> >  talking to file and web servers. Thus, while disk timing might be an> >  attractive source of entropy, it can't be used in a typical server> >  environment without great caution.> > This is something to be concerned about, to be sure.  But generally a> client won't have complete control of the drive head movement ---> there are other clients involved --- and the adversary generally won't> have complete knowledge of the block allocation of files, for example,> so he/she would not be able to characterize the disk drive timings to> the degree of accuracy required.No. But if I manage to break into the firewall protecting a webserver,I can likely arrange for that server to have no other clients for someperiod. Also, see tools like dsniff, which can effectively change thetopology of switched LANs.> Certianly a major concern that I've always had is measuring network> device interrupts, since packet arrial times can be measured by an> outsider.  Such an attack would require that the adversary have a> sophisticated device on the local LAN segment of the attack victim> (since the attacker needs to see all of the packets directed at the> victim in order to make guesses about the inter-packet arrival times,> however.  So the how practical this attack might be is certainly quite> debatable.A broken x86 firewall is quite probably capable of such measurement onan owned 100baseT switched network.> >  (Incidentally, tricks like Matt Blaze's truerand clock drift> >  technique probably don't work on most PCs these days as the> >  "realtime" clock source is often derived directly from the> >  bus/PCI/memory/CPU clock.)> > Actually, many peripherals do have their own clock crystals and clock> circuitry (network cards, serial cards, IDE disks, etc.)..True, but many of those clocks are effectively invisible, being behinda PCI or slower bus, being non-programmable, and modern interfacelogic having buffering clocked to compensate for bus contention. > > Batching> > > >  Samples to be mixed are batched into a 256 element ring> >  buffer. Because this ring isn't allowed to wrap, it's dangerous to> >  store untrusted samples as they might flood out trusted ones.> > It's not dangerous in the sense that we might suffer a security breach> (assuming that our entropy estimation routines are accurate).  It's a> bad thing in that we might lose some good randomness, but that's not a> disaster.> > That being said, if we are running out space in the ring buffer, it> would be good to increase its size.In my patches, untrusted samples outnumber trusted ones by over 10 to1. Kick in entropy for network at gigabit rates (some fraction of 80kpackets per second) and the mixing overhead for the larger pool startsgetting painful. If we need more entropy than a bit per sample *sizeof(batch pool) * HZ (=256000bps!), I think we ought to buy a fewhardware RNGs. I'm actually tempted to make the ring buffer or themixing rate smaller - we're really not going to have 100k real entropyevents/sec.(Let's try to narrow the scope of this a bit, please.)--  "Love the dolphins," she advised him. "Write by W.A.S.T.E.." -To unsubscribe from this list: send the line "unsubscribe linux-kernel" inthe body of a message to majordomo@vger.kernel.orgMore majordomo info at  http://vger.kernel.org/majordomo-info.htmlPlease read the FAQ at  http://www.tux.org/lkml/`