mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [Kernel-janitors] mm/slab.c: linux 2.6.1 fix 2 unguarded kmalloc and a PAGE_SHIFT
       [not found] <vines.sxdD+dlw=B2?= =?ISO-8859-1?Q?+A@SZKOM.BFS.DE>
@ 2004-01-29  2:35 ` Matthew Wilcox
  0 siblings, 0 replies; only message in thread
From: Matthew Wilcox @ 2004-01-29  2:35 UTC (permalink / raw)
  To: Walter Harms; +Cc: kernel-janitors, linux-kernel

On Sun, Jan 25, 2004 at 03:02:24PM +0100, Walter Harms wrote:
> Hi list,
> this fixes catches 2 unguarded kmallocs() and changes a statement so that PAGE_SHIFT >20 causes a warning. 
> At least sparc64 is prepared for a  PAGE_SHIFT >20.

> -       if (num_physpages > (32 << 20) >> PAGE_SHIFT)
> +       if (num_physpages > (32 << (20-PAGE_SHIFT) )

Erm, that's a bad change to make.  There's nothing wrong with having
a PAGE_SHIFT of >20, and this code would still work ... but with your
change it's now undefined behaviour.  Please don't make this change.

(worked examples:

1. suppose we have a PAGE_SHIFT of 24 (16MB page size), the original
code shifts 32 left by 20 then right by 24, net result a right shift of
4 => 2.  Since any machine with a 16MB page size is going to have more
than 2 pages, we're fine.  the new code will shift 32 left by -4 which
is undefined.  bad.

2. suppose we have a PAGE_SHIFT of 26 (64MB page size), the original
code shifts right by 6, result 0.  Since the number of pages is > 0
(one hopes ;-), the test will also succeed as desired.

)

-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-01-29  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <vines.sxdD+dlw=B2?= =?ISO-8859-1?Q?+A@SZKOM.BFS.DE>
2004-01-29  2:35 ` [Kernel-janitors] mm/slab.c: linux 2.6.1 fix 2 unguarded kmalloc and a PAGE_SHIFT Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®