[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140718215054.GD18775@thunk.org>
Date: Fri, 18 Jul 2014 17:50:54 -0400
From: Theodore Ts'o <tytso@....edu>
To: Hannes Frederic Sowa <hannes@...essinduktion.org>,
Dave Jones <davej@...hat.com>,
Linux Kernel <linux-kernel@...r.kernel.org>,
Greg Price <price@....EDU>
Subject: Re: [PATCH] random: check for increase of entropy_count because of
signed conversion
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 majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists