Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-19 Thread Pavel Machek
Hi1 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -4364,6 +4353,15 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned > int order, int preferred_nid, > gfp_t alloc_mask; /* The gfp_t that was actually used for > allocation */ > struct a

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-16 Thread Dmitry Vyukov
that we only check for an out of bound order in the slow >> path and the node reclaim might happen from the fast path already. This >> is fixable by making sure that kvmalloc doesn't ever use kmalloc for >> requests that are larger than KMALLOC_MAX_SIZE but this also shows

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Michal Hocko
On Tue 13-11-18 15:29:41, Andrew Morton wrote: [...] > But do we really need to do this? Are there any other known potential > callsites? The main point is that the code as it stands is quite fragile, isn't it? Fixing up all the callers is possible but can you actually think of a reason why this

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Vlastimil Babka
On 11/14/18 12:32 AM, Andrew Morton wrote: > On Wed, 14 Nov 2018 00:23:28 +0100 Vlastimil Babka wrote: > >> On 11/14/18 12:15 AM, Andrew Morton wrote: >>> On Tue, 13 Nov 2018 10:43:05 +0100 Michal Hocko wrote: >>> --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4364,6 +4353,15 @@

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Andrew Morton
On Wed, 14 Nov 2018 00:23:28 +0100 Vlastimil Babka wrote: > On 11/14/18 12:15 AM, Andrew Morton wrote: > > On Tue, 13 Nov 2018 10:43:05 +0100 Michal Hocko wrote: > > > >> --- a/mm/page_alloc.c > >> +++ b/mm/page_alloc.c > >> @@ -4364,6 +4353,15 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Andrew Morton
this also shows that > the code is rather fragile. A recent UBSAN report just underlines that > by the following report > > UBSAN: Undefined behaviour in mm/page_alloc.c:3117:19 > shift exponent 51 is too large for 32-bit type 'int' > CPU: 0 PID: 6520 Comm: syz-exe

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Vlastimil Babka
On 11/14/18 12:15 AM, Andrew Morton wrote: > On Tue, 13 Nov 2018 10:43:05 +0100 Michal Hocko wrote: > >> --- a/mm/page_alloc.c >> +++ b/mm/page_alloc.c >> @@ -4364,6 +4353,15 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int >> order, int preferred_nid, >> gfp_t alloc_mask; /* The gfp_

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Andrew Morton
On Tue, 13 Nov 2018 10:43:05 +0100 Michal Hocko wrote: > Konstantin has noticed that kvmalloc might trigger the following warning > [Thu Nov 1 08:43:56 2018] WARNING: CPU: 0 PID: 6676 at mm/vmstat.c:986 > __fragmentation_index+0x54/0x60 > [...] > [Thu Nov 1 08:43:56 2018] Call Trace: > [Thu No

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-13 Thread Michal Hocko
ble by making sure that kvmalloc doesn't ever use kmalloc for requests that are larger than KMALLOC_MAX_SIZE but this also shows that the code is rather fragile. A recent UBSAN report just underlines that by the following report UBSAN: Undefined behaviour in mm/page_alloc.c:3117:19 shift exp

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Balbir Singh
On Fri, Nov 09, 2018 at 10:56:04AM +0100, Michal Hocko wrote: > On Fri 09-11-18 18:41:53, Tetsuo Handa wrote: > > On 2018/11/09 17:43, Michal Hocko wrote: > > > @@ -4364,6 +4353,17 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned > > > int order, int preferred_nid, > > > gfp_t alloc_mask; /* T

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Michal Hocko
On Fri 09-11-18 19:24:48, Tetsuo Handa wrote: > On 2018/11/09 19:10, Vlastimil Babka wrote: + * reclaim >= MAX_ORDER > areas which will never succeed. Callers may > + * be using allocators in order of preference for an area that > is > + * too large. >

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Tetsuo Handa
On 2018/11/09 19:10, Vlastimil Babka wrote: +* reclaim >= MAX_ORDER areas which will never succeed. Callers may + * be using allocators in order of preference for an area that is + * too large. + */ + if (order >= MAX_ORDER) { >>> >>> Also, why not to add BUG

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Michal Hocko
On Fri 09-11-18 19:07:49, Tetsuo Handa wrote: > On 2018/11/09 18:56, Michal Hocko wrote: > > Does this following look better? > > Yes. > > >> Also, why not to add BUG_ON(gfp_mask & __GFP_NOFAIL); here? > > > > Because we do not want to blow up the kernel just because of a stupid > > usage of the

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Michal Hocko
On Fri 09-11-18 11:10:00, Vlastimil Babka wrote: > On 11/9/18 10:56 AM, Michal Hocko wrote: > > On Fri 09-11-18 18:41:53, Tetsuo Handa wrote: > >> On 2018/11/09 17:43, Michal Hocko wrote: > >>> @@ -4364,6 +4353,17 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned > >>> int order, int preferred_ni

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Vlastimil Babka
On 11/9/18 10:56 AM, Michal Hocko wrote: > On Fri 09-11-18 18:41:53, Tetsuo Handa wrote: >> On 2018/11/09 17:43, Michal Hocko wrote: >>> @@ -4364,6 +4353,17 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int >>> order, int preferred_nid, >>> gfp_t alloc_mask; /* The gfp_t that was actually

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Tetsuo Handa
On 2018/11/09 18:56, Michal Hocko wrote: > Does this following look better? Yes. >> Also, why not to add BUG_ON(gfp_mask & __GFP_NOFAIL); here? > > Because we do not want to blow up the kernel just because of a stupid > usage of the allocator. Can you think of an example where it would > actuall

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Michal Hocko
On Fri 09-11-18 18:41:53, Tetsuo Handa wrote: > On 2018/11/09 17:43, Michal Hocko wrote: > > @@ -4364,6 +4353,17 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int > > order, int preferred_nid, > > gfp_t alloc_mask; /* The gfp_t that was actually used for allocation */ > > struct alloc

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Mel Gorman
On Fri, Nov 09, 2018 at 09:43:53AM +0100, Michal Hocko wrote: > On Thu 08-11-18 23:09:23, Kyungtae Kim wrote: > > We report a bug in v4.19-rc2 (4.20-rc1 as well, I guess): > > > > kernel config: https://kt0755.github.io/etc/config_v2-4.19 > > repro: https://kt0755.github.io/etc/repro.c4074.c > >

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Tetsuo Handa
On 2018/11/09 17:43, Michal Hocko wrote: > @@ -4364,6 +4353,17 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int > order, int preferred_nid, > gfp_t alloc_mask; /* The gfp_t that was actually used for allocation */ > struct alloc_context ac = { }; > > + /* > + * In the

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Michal Hocko
vmalloc doesn't ever use kmalloc for requests that are larger than KMALLOC_MAX_SIZE but this also shows that the code is rather fragile. A recent UBSAN report just underlines that by the following report UBSAN: Undefined behaviour in mm/page_alloc.c:3117:19 shift exponent 51 is too

Re: UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-09 Thread Vlastimil Babka
========= > UBSAN: Undefined behaviour in mm/page_alloc.c:3117:19 > shift exponent 51 is too large for 32-bit type 'int' > CPU: 0 PID: 6520 Comm: syz-executor1 Not tainted 4.19.0-rc2 #1 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01

UBSAN: Undefined behaviour in mm/page_alloc.c

2018-11-08 Thread Kyungtae Kim
that order is controllable by user input via raw_cmd_ioctl without its sanity check, thereby causing memory problem. To stop it, we can use like MAX_ORDER for bounds check before using it. = UBSAN: Undefined behaviour in mm/page_alloc.c:3117:19 shift exponent