Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5990548imu; Tue, 13 Nov 2018 15:16:35 -0800 (PST) X-Google-Smtp-Source: AJdET5e95I22RO2nGNi0X2xHCx5nXa06amhotveIdsgOtMBGf9fDbyu05G61bVbc9XROvNiJhUqW X-Received: by 2002:a17:902:2006:: with SMTP id n6-v6mr7180488pla.131.1542150995499; Tue, 13 Nov 2018 15:16:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542150995; cv=none; d=google.com; s=arc-20160816; b=De92UcLq9HOqSW/n9Cnw0iF2XPkdsREHBsPupIziI5t1XPl+k/sZbLs6n+KwQQ7Rrb yOpP67EEmTTtXp0N2HxBvoLxn6ZTLHA9OvG0ehqYWZFZul7iKczkJfxJNgkmj1TwZD8a KMvKMeJCpjLinB0vToXDcoXod/QxmHagG9kmWHK/vfPbpj123Zk7FQicwqFF2s7s6cZc nhH7nCkIQVjgn8Or3gIMPqpZPSjE1DHQS5u6Oo5rFBq87NdVX0YTm3ZhCn8LFO3upbmM Pzz594ZAMr2sPwg667PZkqNxaSdy4w4FYY674rVUpU7sfZ4XpJAyOWq6CxhDArCQ2+Bt HeSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=oY+VQFPCIpJiLt3dvcKjhozErNCq2EoRO/oVq4qXN5E=; b=rwEnvzkmjzwZW5AHIk6D+BfJrImAOJAUgymS1WAajbsPcVCx2GcY7CxCLlApWzRKwL 4PHPQ6f590vH3c5B5BK/D0p1H2ffMpgqwUVMD77k+tXtd/+PBgjXgsUP6jUxnu80S7eI S+N8ROeg0lbr/CJ0fiHeFfNuUeDGI/hfvCYLbiQbeRabmIrF1mS1cJNtGQjo3IqeLou3 wwFI8QSF546aTTicwk4tum8LgUKzsYDJp8qtGR6U1qrqGCt60yIsCR1gVTz42eV1GfdG ywEMnq1BIj7ormRnFqvwMvX5aKmbXqZ8xRl/VjGA0AAirXB4UuGQxkadd9PKFzh4cjXy G0mQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15-v6si24770063plk.269.2018.11.13.15.16.17; Tue, 13 Nov 2018 15:16:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731768AbeKNJPf (ORCPT + 99 others); Wed, 14 Nov 2018 04:15:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52570 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbeKNJPf (ORCPT ); Wed, 14 Nov 2018 04:15:35 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0F2F3A92; Tue, 13 Nov 2018 23:15:05 +0000 (UTC) Date: Tue, 13 Nov 2018 15:15:03 -0800 From: Andrew Morton To: Michal Hocko Cc: Kyungtae Kim , pavel.tatashin@microsoft.com, vbabka@suse.cz, osalvador@suse.de, rppt@linux.vnet.ibm.com, aaron.lu@intel.com, iamjoonsoo.kim@lge.com, alexander.h.duyck@linux.intel.com, mgorman@techsingularity.net, lifeasageek@gmail.com, threeearcat@gmail.com, syzkaller@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Konstantin Khlebnikov Subject: Re: UBSAN: Undefined behaviour in mm/page_alloc.c Message-Id: <20181113151503.fd370e28cb9df5a0933e9b04@linux-foundation.org> In-Reply-To: <20181113094305.GM15120@dhcp22.suse.cz> References: <20181109084353.GA5321@dhcp22.suse.cz> <20181113094305.GM15120@dhcp22.suse.cz> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Nov 1 08:43:56 2018] fragmentation_index+0x76/0x90 > [Thu Nov 1 08:43:56 2018] compaction_suitable+0x4f/0xf0 > [Thu Nov 1 08:43:56 2018] shrink_node+0x295/0x310 > [Thu Nov 1 08:43:56 2018] node_reclaim+0x205/0x250 > [Thu Nov 1 08:43:56 2018] get_page_from_freelist+0x649/0xad0 > [Thu Nov 1 08:43:56 2018] ? get_page_from_freelist+0x2d4/0xad0 > [Thu Nov 1 08:43:56 2018] ? release_sock+0x19/0x90 > [Thu Nov 1 08:43:56 2018] ? do_ipv6_setsockopt.isra.5+0x10da/0x1290 > [Thu Nov 1 08:43:56 2018] __alloc_pages_nodemask+0x12a/0x2a0 > [Thu Nov 1 08:43:56 2018] kmalloc_large_node+0x47/0x90 > [Thu Nov 1 08:43:56 2018] __kmalloc_node+0x22b/0x2e0 > [Thu Nov 1 08:43:56 2018] kvmalloc_node+0x3e/0x70 > [Thu Nov 1 08:43:56 2018] xt_alloc_table_info+0x3a/0x80 [x_tables] > [Thu Nov 1 08:43:56 2018] do_ip6t_set_ctl+0xcd/0x1c0 [ip6_tables] > [Thu Nov 1 08:43:56 2018] nf_setsockopt+0x44/0x60 > [Thu Nov 1 08:43:56 2018] SyS_setsockopt+0x6f/0xc0 > [Thu Nov 1 08:43:56 2018] do_syscall_64+0x67/0x120 > [Thu Nov 1 08:43:56 2018] entry_SYSCALL_64_after_hwframe+0x3d/0xa2 > > ... > > --- 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 alloc_context ac = { }; > > + /* > + * There are several places where we assume that the order value is sane > + * so bail out early if the request is out of bound. > + */ > + if (unlikely(order >= MAX_ORDER)) { > + WARN_ON_ONCE(!(gfp_mask & __GFP_NOWARN)); > + return NULL; > + } > + I know "everybody enables CONFIG_DEBUG_VM", but given this is fastpath, we could help those who choose not to enable it by using #ifdef CONFIG_DEBUG_VM if (WARN_ON_ONCE(order >= MAX_ORDER && !(gfp_mask & __GFP_NOWARN))) return NULL; #endif (Again curses 91241681c62 ("include/linux/mmdebug.h: make VM_WARN* non-rvals"))