On Fri, Jul 18, 2014 at 05:25:04PM -0400, Theodore Ts'o wrote:
> > As indicated by credit_entropy_bits entropy_count cannot get negative,
> > so I don't see any reason to include a check for entropy_count < 0
> > here. Do you agree?
> 
> No, the check is important; after we subtract ibytes << (ENTROPY_SHIFT
> + 3) we could drive entropy_count negative, and we don't want to
> trigger the WARN_ON().
> 
> I'll modify the patch to keep the check.

Never mind, I took a closer look at the your patch, and I now
understand what you were asking.  Since entropy_count should never
_start_ negative, simply checking to see if entropy_count > nfrac is
sufficient.

However, there's something a bit larger hiding here, which is we
shouldn't allow urandom_read to be passed a which is greater than
INT_MAX >> ENTROPY_SHIFT.  Otherwise, the nfrac calcuation will
overflow, which can also result in too little entropy getting removed.

The other problem is that comparing since entropy_count is an int, and
nfrac is a size_t, this is a signed vs. unsigned comparison, which
will raise compiler warnings.  

Let me know what you think of my revised patch, which should hopefully
add enough checks to be sufficiently paranoid.  :-)

                                                        - Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to