From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796053604; b=iUxY1V6YhA0o629m4JqXjFTXZTHcrCHeyTPG88jEUGy3Otdzd78WhU5J1rn5EgHd4os0 DFqCO/SGurYCy8WHsZK4Q4AOlwlVc5ykcUqJUeP0Av3ZzZyRLfHgvyKl9AE8NrhIil1Yq z019g/kgRNcfIPGeNEi+L8xud86VsVcVGed4SU7Xcn+zV5PdlYzskcrUZzdd48vEpR0io DA5d7B3m/0i5C1OT7nwAW4GSefI2p2kM9QmPDrX+2O9pIa03K2FLUuARP1E/c0d85dTqa 5HdZ3ZXUDiJ2OTRlOiTV8DjGCanYddBS4C8+/ZN68FFzBpxyOhB6O5Zx9n23tnUR+EA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053604; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ob3Oibo0VXohLyuh/Gwt7SYScMXtP/VlvpJiqod7hpg=; b=cUN51vhEl1W7X3QRClgWPjHy7sHAiAO5MlSu64ZcP4zTmMTyfTrVMVVij8bwbhEE13PY UdjnG6DajqdJTvaV911eBWUseGkIcfeHmOuLyzIieZX81rC2Htm+/G6YAqVaxm67DKtyC L/OkCV3nOg4Dp+fm6xT6B6jiqTDaplh6Za5O+JAZ42K3q1pBmWo3wDPqXC/NY3J6+rp6/ VjkSVutqd+LqmFc6hl1hyma+KCWI3xMcA/SDg7AOAYb019WFjoICuf2MQsZo/P6CYAbAF P2ACptL6QyjvT4UEzORBtD7S8kMa6VbMxpLyqdq6SpYo59o5SogNXFyGsqtR1jamQFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xkQh9wpt; arc=none smtp.remote-ip=209.85.210.47 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF8EA606A68F for ; Mon, 30 Nov 2026 15:46:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF8EA606A68F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xkQh9wpt Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-86156cf8a7eso8207737a34.1 for ; Mon, 30 Nov 2026 07:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796053603; x=1796658403; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ob3Oibo0VXohLyuh/Gwt7SYScMXtP/VlvpJiqod7hpg=; b=xkQh9wptjMCny9iXyqYOKogdJkr5K75yOwmwptxWXh4ls6jSoe2CV1GHaWHXTSvnkD VW7HwUO9vl4D6u4+hAzn/Xfc15ZEiV/Ak2qf7r/ejx7xMiXuMZMfM9rzHpIfYsTk+1W8 GfkWsg5bmWOO8QoltVNu/M5v1IMo0S+fpq2UheWe/lPtDpPPvovUAHdVAEy0TvYoR6+i loWyHa2ak76b7e7K4Kn8g1uD+Umv24rXy8JvNkTgVING3wu0Ggpc+PE6UJu1pCHSc81k 2ziqcDsfd3dmRwxV5RgeeuZTBMAwB/kfIgqNwJ+lIOyzh+ohzzxnBlibSN8/5Xcmwj90 ShbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796053603; x=1796658403; h=in-reply-to:content-disposition:content-type:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=ob3Oibo0VXohLyuh/Gwt7SYScMXtP/VlvpJiqod7hpg=; b=XHoNHE+4qO+oqS9B2uP5w5gwPXXQY2csSkWFAjTZs5/RHSOBD1HjxSi5zvWmFXnnwj T8f5i82hOlDXZkiUXFuBa5mfkEFEchmKayVyATk5QICq5o+qVGf3lJ16V7jt5s1jdDVI AcKnhcoB8H1QpwgPrR2UL6WRpOAALibNJHOQO2aOsFF9RJiYfTUwV7i7e5UVnxiBEITf DC2pYIn19q2VK+Wtz7XLWjYHsfAfvGEOA/31k6SKHA4DTz+dgR0MEOEkXEUpbBbH2223 2/xl0zSzdG7BWNpwyoFZpPE64GTR3DFBE3Kj2TqaC6yOLfNK00Y3s/A9jvHCV1kIpvXz 5z+g== X-Forwarded-Encrypted: i=1; AL+hErFIUefipbMY7w6kA9zcph8NiDrl0u3bOeZ2YDgkzZB8nEigX5kDVBvds3fUvqTMsWOeZrwrDhmvHLM=@vger.kernel.org X-Gm-Message-State: APuU4Z/LONCww/i7ZSYq/FwSaJ/Ihv480Yd2rllH/7IVpXSaoYy63pB7 FYkYhSLahHwMiWH2GGcS7e0uIwF1XzJYl1UfBkfzX6Pq4r2J8x2IuCPT X-Gm-Gg: AZFdTZcOno7kaWypM52ZmqrKjRERaih9uY5mYyUufeRbt9oz+v+9Xi3zZ1QkS0Kppnw VS3TehV3/pBU1m8GaEsQAgkA394YzUyV6b9zHWec48HJGJDBLxltiL9hQ5rLmqKjqMUxaFS0D/e Kq+MNIr8qRW1bH91EUT9s/1a3LdN4HdLYD18ug7gjGk36Swi1eumyn4FeK3YSlIQJm4xhAMk6uG 3IqZTepyg8iGZqdFGyWvZPCIr1WzSMEriY9r/Ls2OKMJd3V09SyQrHZhhXP0FTzUukX1BRndTKw ReQ9YZLepU70r1IoONamTXzkRaXepMxH1/rNsD/Zg4n19QHWONrI6rQzH/gEItR7dxGgQY+bT5+ T3HdvKzQc2mlV9Q71bMwHs8nVWvPsHKPyus1T6NOLvacKZ9rrsQPZ7JhzQF/yf0TgT/jVm6Lqv4 A720Q0uYuR+jTl5zw7OB2PkomWuJqWP86uoQn9FqYx0gQbLrqhLufcFctydVzDjT38mYXQH3nMU 6fD4E7neyIfizCqH3/diq5mg4P9J+155rzxgtKCTXYfvGiQsztKf8nKTwCEp/+nad0hhlqdUDUK n/euDm4L/qNEEHU5Gelxtez6OQnQzxJhMYfk4hDxhcnHUOLxkk1+ILV9QrG1c8WPQAZUfZ+wsIE FipaJ7A== X-Received: by 2002:a05:6820:4dc2:b0:6f5:a844:b12 with SMTP id 006d021491bc7-71b327c8826mr24013192eaf.57.1796053602669; Mon, 30 Nov 2026 07:46:42 -0800 (PST) Received: from localhost ([2a03:2880:10ff:13::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc60491337sm28183537fac.12.2026.11.30.07.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 07:46:42 -0800 (PST) Date: Mon, 30 Nov 2026 07:46:41 -0800 From: Joshua Hahn To: "David Hildenbrand (Arm)" Cc: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , Chris Mason , stable@vger.kernel.org Subject: Re: [PATCH 24/32] mm/mempolicy: reject an empty set of allowed nodes Message-ID: Mail-Followup-To: "David Hildenbrand (Arm)" , Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , Chris Mason , stable@vger.kernel.org References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-24-f66094116801@kernel.org> X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261129-fixes_core_3-v1-24-f66094116801@kernel.org> On Sun, Nov 29, 2026 at 11:06:55AM +0100, David Hildenbrand (Arm) wrote: > From: Chris Mason > > Installing a mempolicy with MPOL_F_RELATIVE_NODES can trigger a division > by zero when racing with memory offlining. I managed to reproduce this > in a small VM with excessive set_mempolicy() calls while offlining > memory: > > Oops: divide error: 0000 [#1] SMP > RIP: 0010:bitmap_fold+0x43/0x60 > Call Trace: > ? mpol_relative_nodemask+0x26/0x40 > ? mpol_set_nodemask+0x43/0x90 > ? do_set_mempolicy+0x5e/0xe0 > ? __x64_sys_set_mempolicy+0x6c/0x80 > > mpol_set_nodemask() intersects current->mems_allowed with N_MEMORY, and > mpol_relative_nodemask() folds the user's nodemask modulo the weight of > the result. > > If memory offlining just cleared the task's only allowed node in N_MEMORY, > but cpuset did not update mems_allowed yet, the intersection is empty and > nodes_fold() divides by zero. > > do_mbind() and mpol_shared_policy_init() call mpol_set_nodemask() as > well. > > Let's fix it by failing with -EINVAL early if there is no allowed node > with memory, just like ->create() would later fail for an empty nodemask. Hi David, LGTM! Reviewed-by: Joshua Hahn > The same division by zero was originally reported by syzkaller for > mpol_rebind_mm() [1]. The discussion of Yury's fix attempt [2] also > identified this path in mpol_set_nodemask() [3], but only the rebind > path got fixed, by commit b983c5642638 ("cgroup/cpuset: rebind mm mempolicy > to effective_mems, not mems_allowed"). > > This has low urgency, as it is extremely unlikely to hit in practice. > > Fixes: 8fe23e057172 ("mm: clear node in N_HIGH_MEMORY and stop kswapd when all memory is offlined") > Cc: stable@vger.kernel.org > Reported-by: David Hildenbrand (Arm) > Closes: https://lore.kernel.org/all/fe33c767-ea11-43e2-8732-f752c9c1205c@kernel.org/ [3] > Link: https://lore.kernel.org/all/CA+0ovCgxbZkXa+OU8w3s84R3KNPNxxRfmsNR-udh+afQBbGNmw@mail.gmail.com/ [1] > Link: https://lore.kernel.org/all/20260528190337.878027-1-ynorov@nvidia.com/ [2] > Signed-off-by: Chris Mason > [ david: update description and comment; add reproduction details ] > Signed-off-by: David Hildenbrand (Arm) > --- > mm/mempolicy.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index 1f68a463b3bc7..746fd0a137515 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -491,9 +491,13 @@ static int mpol_set_nodemask(struct mempolicy *pol, > if (!pol || pol->mode == MPOL_LOCAL) > return 0; > > - /* Check N_MEMORY */ > - nodes_and(nsc->mask1, > - cpuset_current_mems_allowed, node_states[N_MEMORY]); > + /* > + * If we just offlined the last memory on a node, it might be gone from > + * N_MEMORY before cpuset updates mems_allowed. Just fail in that case. > + */ > + if (!nodes_and(nsc->mask1, > + cpuset_current_mems_allowed, node_states[N_MEMORY])) > + return -EINVAL; > > VM_BUG_ON(!nodes); > > > -- > 2.56.1 >