Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3417728imu; Mon, 19 Nov 2018 15:58:51 -0800 (PST) X-Google-Smtp-Source: AJdET5dYUrh9QFeqZ2Muzf+cek1GDvT0VStVVHgLeXBpNGt8o5d1aRPZhfNYB1i8AtwrFxCUgSS5 X-Received: by 2002:a17:902:24d:: with SMTP id 71mr18467944plc.225.1542671931132; Mon, 19 Nov 2018 15:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542671931; cv=none; d=google.com; s=arc-20160816; b=e73/GO8d7u7X/44eWiH41RxATEv/M2CeN1JDuTUXbdFwfbFfDAfZUpSyjiLj7FI+JH MQdDySrdkHh/I2IjGXBExWMRRNJG+bzPDCVdEXs12pepo1cXjCeqMs5qVqcHaatLBbYK Hp4DOGasWeqxzss1F5Ff0qotitTJNnLsp3z2owyk/IpzjOBzrf5C31pWaT5+rygGsTBl KZMMbcEkEcO9iaQW+y/Mnup8mvK1fO2y/lEO1C9G+/m7wvYz9/7Ivasz9iWduTc48rjU KKUil8kKx4m2+cm8smP31PAkeTALh6HyzvPpYldbXiUaMbexHMx9FjbGCmQPI7aZsF92 +puw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=onvswolie+uh/LPAYrCUJars4n/dYnyVQ6t9Ty/uUxg=; b=Ib49F5CoOYl/krwcy8J8AuNhsOxSHDubPIvLXa5aTvXaaWTnD4cpYDFGZhHj20uDMs +eH/r93qSyjpWLkHXaPTiLZBgGTJNBh0b2Tn8mxM26Iset2m2jm3CLxy+Sr5xRFcX8vB oUA7cmFkKuOups6lLoidLnXStMMcLoVB2u1CcFFXiwBbVmyPNJ/qgtcw+NjLL1B1Kf7/ lqz3tjD64OtIo7cXL0uGAcBOC6Fr91g2iqJssLiL9hhc3HC9xlYwflPppRbjoNuJRk+w JBEvzWNWusvc65Dwp9HgxXLd75AXER8vUF1rNQXVYx2bqORzppWaE48ZPg1BGmzV/YGS igMg== 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 v16-v6si41524071plo.417.2018.11.19.15.58.36; Mon, 19 Nov 2018 15:58:51 -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 S1732215AbeKTKYA (ORCPT + 99 others); Tue, 20 Nov 2018 05:24:00 -0500 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:35430 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727583AbeKTKYA (ORCPT ); Tue, 20 Nov 2018 05:24:00 -0500 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 3B2B28090E; Tue, 20 Nov 2018 00:57:46 +0100 (CET) Date: Tue, 20 Nov 2018 00:57:48 +0100 From: Pavel Machek To: Vlastimil Babka Cc: Andrew Morton , Michal Hocko , Kyungtae Kim , pavel.tatashin@microsoft.com, 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: <20181119235748.GC7367@amd> References: <20181109084353.GA5321@dhcp22.suse.cz> <20181113094305.GM15120@dhcp22.suse.cz> <20181113151503.fd370e28cb9df5a0933e9b04@linux-foundation.org> <20181113153204.ea0c0895866838de9e3bc8d0@linux-foundation.org> <1f4439c8-d669-a1ac-53f5-36c04da72a51@suse.cz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZwgA9U+XZDXt4+m+" Content-Disposition: inline In-Reply-To: <1f4439c8-d669-a1ac-53f5-36c04da72a51@suse.cz> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ZwgA9U+XZDXt4+m+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi1 > >>>> --- a/mm/page_alloc.c > >>>> +++ b/mm/page_alloc.c > >>>> @@ -4364,6 +4353,15 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsign= ed int order, int preferred_nid, > >>>> gfp_t alloc_mask; /* The gfp_t that was actually used for allocati= on */ > >>>> struct alloc_context ac =3D { }; > >>>> =20 > >>>> + /* > >>>> + * There are several places where we assume that the order value i= s sane > >>>> + * so bail out early if the request is out of bound. > >>>> + */ > >>>> + if (unlikely(order >=3D MAX_ORDER)) { > >>>> + WARN_ON_ONCE(!(gfp_mask & __GFP_NOWARN)); > >>>> + return NULL; > >>>> + } > >>>> + > >>> > >>> I know "everybody enables CONFIG_DEBUG_VM", but given this is fastpat= h, > >>> we could help those who choose not to enable it by using > >>> > >>> #ifdef CONFIG_DEBUG_VM > >>> if (WARN_ON_ONCE(order >=3D MAX_ORDER && !(gfp_mask & __GFP_NOWARN))) > >>> return NULL; > >>> #endif > >> > >> Hmm, but that would mean there's still potential undefined behavior for > >> !CONFIG_DEBUG_VM, so I would prefer not to do it like that. > >> > >=20 > > What does "potential undefined behavior" mean here? >=20 > I mean that it becomes undefined once a caller with order >=3D MAX_ORDER > appears. Worse if it's directly due to a userspace action, like in this > case. We should really check if value from userspace is sane _before_ passing it to alloc_pages(). Anything else is too fragile. Maybe alloc_pages should do the second check, but... Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --ZwgA9U+XZDXt4+m+ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlvzTfwACgkQMOfwapXb+vJrxQCfQWRQidsCidtn9kylt9QlaV9b HX8AoJNp4zXtXxXm0nbOi7G27O/MZVJy =y6KK -----END PGP SIGNATURE----- --ZwgA9U+XZDXt4+m+--