Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp544939imu; Fri, 9 Nov 2018 01:56:55 -0800 (PST) X-Google-Smtp-Source: AJdET5ecLoeeNkVbQBnLXzlBSSFryxWlvCSbjR7Z9ND/sVVBnppMdhr9HZXVoPSxF1FGqEPBHqR9 X-Received: by 2002:a17:902:8648:: with SMTP id y8-v6mr5261407plt.159.1541757415284; Fri, 09 Nov 2018 01:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541757415; cv=none; d=google.com; s=arc-20160816; b=RQtdAy0AMQ1kzYCN2aPoYX5Gdqrt4/wuFJ9wbMi6tWPajwfSTDnmN1nssy8wqL1Rg1 6iAGwsHVw5mhBy9pF3U8K6BGIj7nuns61ZVyh4KrBma+DxB2mJKSqrLBzaza2XERCOFJ eJb2E0U3x28pA8LCZMDDgVLBczJHFtfBe+ChGMhtjqdNaSuX3tyxMKmtVUUtvcv0xvt6 MuNQBrxWd/MIEcXG8mVqrWz9tLuME9hQZQvgWY9R1Ywo13eXi+071SCgzfx6sCsxiTzA nWOcaZZDPWotUv5XpUCKxRRWbIjmH9C8+M2y0RyBheY3/ehD6C5BWXABOwql70QyKMay fUNg== 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=KONjsWYiQYUYMdcHkULa4KqpLvdzgInu1ebbFD75XVM=; b=NQLw48+Ldwt5LCiXASjbIiX6jIMe3OhbwnSL0iROymXHR55IVt/LeEarABaArYl+26 R5FDlg1zxEjDrU/MrdW1EkJNtioSNJ8tF3HpT8Y9DtRvxyADlUBog/waXuw7NPckMZl8 yaAH5uei5URe0D/RwwYOlf4AS3W0nlzJ4A2eYd8P3DGh29MTpHt08AVZ6K3oZJ5OfMgK iVp5uSBzJdIZbF9eME9ygqYyBF9HoIwzUiRdW0Xr3zvW9i1JOsVq026tfEsygoWhH9OG zty0WIbOfHl3wLulYfbFsqWUI14w0UUpWMsgfhsnTrczq96APbUaXMYa8k4ly57AYH0z 2rUA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si5979131pgi.0.2018.11.09.01.56.40; Fri, 09 Nov 2018 01:56:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbeKITf6 (ORCPT + 99 others); Fri, 9 Nov 2018 14:35:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:39800 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727537AbeKITf5 (ORCPT ); Fri, 9 Nov 2018 14:35:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AE4D6ADDD; Fri, 9 Nov 2018 09:56:06 +0000 (UTC) Date: Fri, 9 Nov 2018 10:56:04 +0100 From: Michal Hocko To: Tetsuo Handa Cc: Kyungtae Kim , akpm@linux-foundation.org, 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: <20181109095604.GC5321@dhcp22.suse.cz> References: <20181109084353.GA5321@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_context ac = { }; > > > > + /* > > + * In the slowpath, we sanity check order to avoid ever trying to > > Please keep the comment up to dated. Does this following look better? diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9fc10a1029cf..bf9aecba4222 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4354,10 +4354,8 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid, struct alloc_context ac = { }; /* - * In the slowpath, we sanity check order to avoid ever trying to - * reclaim >= MAX_ORDER areas which will never succeed. Callers may - * be using allocators in order of preference for an area that is - * too large. + * 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 (order >= MAX_ORDER) { WARN_ON_ONCE(!(gfp_mask & __GFP_NOWARN)); > I don't like that comments in OOM code is outdated. > > > + * 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_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 actually make any sense? I would argue that such a theoretical abuse would blow up on an unchecked NULL ptr access. Isn't that enough? -- Michal Hocko SUSE Labs