From patchwork Tue Oct 24 06:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13433980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0936C00A8F for ; Tue, 24 Oct 2023 06:50:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 748626B017F; Tue, 24 Oct 2023 02:50:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F8966B0180; Tue, 24 Oct 2023 02:50:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C0C26B0181; Tue, 24 Oct 2023 02:50:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4988D6B017F for ; Tue, 24 Oct 2023 02:50:48 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 20CD6120DB8 for ; Tue, 24 Oct 2023 06:50:48 +0000 (UTC) X-FDA: 81379432176.25.DE3B0D5 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by imf12.hostedemail.com (Postfix) with ESMTP id 4F77B4000C for ; Tue, 24 Oct 2023 06:50:46 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=kXMxdeO6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of hughd@google.com designates 209.85.128.178 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698130246; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a3C4xL26+by/nNiNIi96kjQArUXkrd2oNhMsXtWit3Y=; b=fa9jXfG/LTPb2b1wARvPW3GA1jh9G5BUy2wkKYhTY04P0Lj1Z4c+9ytLpHFD841cZcCHp8 SxNDXsYqilzBpvWWWsn8ntwse/ArQs/f6U5n5bjQ/FVpQUfEeZ7/EHvZx3IagXcdUabgvQ +pGdrKPnnTJ03OoSaNH8dZnWtuuLrBA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=kXMxdeO6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of hughd@google.com designates 209.85.128.178 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698130246; a=rsa-sha256; cv=none; b=03xLv583DWxa4SeauFibSLYNt6i3Ni+GkSniisHqPvqnyqydyGJlgy9VWD1qgQGqxinldT fk+W4dkNKXLrnXz1iqqtdc1NwN4Pa5k/tJox0nxpRZFQ3aCVysNIJ3VoRSX/03knWwhsuq NTwf3UHXWfYARvkN13l6voWqbpNZoXw= Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-5a81ab75f21so41219057b3.2 for ; Mon, 23 Oct 2023 23:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698130245; x=1698735045; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=a3C4xL26+by/nNiNIi96kjQArUXkrd2oNhMsXtWit3Y=; b=kXMxdeO6/ZpK029c8EbLGh6U7qqFvw2HHuATyemnLugJr19IuG1H2MWTxhZgS4TW1s YJdrgNX+OVl0mATgmY7THHyfu6E0mTZLeiiVUF3sHxUQBxzZ6sGDVSlLRS8YxJn3dgE2 zk1aoekwaXshk5IBV27BPb7YKaJTyqjUOIlDQMeM9PfLvhxjwAYy46E8V1EsOxpgk58I 1U+X2qKvHFXOWS0c7MYNA34BuK5mqJX7DwXcU4WZxIOmTWurQY69c7gem2p9m6Z3gyXe VAmjYJK1hJ7Zz3zAydXBVD8qamRdrPvPpcIRsMPaesPnGBeRUBPHHYyYAfsCdmDrL/kz n6/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698130245; x=1698735045; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a3C4xL26+by/nNiNIi96kjQArUXkrd2oNhMsXtWit3Y=; b=pyanzdaX585TGIukVBwFUHutTdrAKYnETCcbOzZd8YRf5Qe6N7MR6dd1uX9cVltmr7 3X8bfd0rs9OJOIZCeOadFqoYUAYgWCrxNiefknQLZTSu3q7Nyc68O/u2TsQe0Ungy+UG Lz7HVerbvND0gVYuaDrxcObYOkogWMmMUNFJDm9AedCJ390PH1G832QHC5f8QukE5/1j yPAi6GiQfOhy4c1VKTjivwyrgL54RoCU0eekk2bYv8BJtHAOrnH26gjxtlbpr/LzMWC9 /HyGUnraBP4Ehn/VglLLQlAMTIjA5THahVaOHzJ671FxlCrAtsQDmhwFF1f2huCViOoM jZ/Q== X-Gm-Message-State: AOJu0YzExUs6G9Z61ZPpCvzGWFAJyS128s4Tc9q6x11YrVB0OCfCm7F0 8ofi2Ld/pBj1E1+O4H5oKHu87w== X-Google-Smtp-Source: AGHT+IHzuoz/z+GIe/hmLTh1Bx0JUA8EBXee8rMOTjxms3aAhBTqy3zTfa7HbZJDIwVTZL+QLCMlDw== X-Received: by 2002:a81:8441:0:b0:5a7:ba09:e58b with SMTP id u62-20020a818441000000b005a7ba09e58bmr12869572ywf.14.1698130245291; Mon, 23 Oct 2023 23:50:45 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id e6-20020a0df506000000b005837633d9cbsm3781211ywf.64.2023.10.23.23.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 23:50:44 -0700 (PDT) Date: Mon, 23 Oct 2023 23:50:42 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Andi Kleen , Christoph Lameter , Matthew Wilcox , Mike Kravetz , David Hildenbrand , Suren Baghdasaryan , Yang Shi , Sidhartha Kumar , Vishal Moola , Kefeng Wang , Greg Kroah-Hartman , Tejun Heo , Mel Gorman , Michal Hocko , "Huang, Ying" , "Liam R. Howlett" , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mempolicy: migration attempt to match interleave nodes: fix In-Reply-To: <77954a5-9c9b-1c11-7d5c-3262c01b895f@google.com> Message-ID: <3311d544-fb05-a7f1-1b74-16aa0f6cd4fe@google.com> References: <77954a5-9c9b-1c11-7d5c-3262c01b895f@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4F77B4000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6psgeu9k9gwj4n8g95mde8jzmaup3m7e X-HE-Tag: 1698130246-893427 X-HE-Meta: U2FsdGVkX1/GrmgvRmtQ+DNej1iTzYXg8sCqi/LPhyCn4S7mvAQCJ0CGuyrd3oSqv4zJrlWev465lw6v7kSgM2SEcygpNMpHexksgivUMafFS6Yf52/X1jJobLjPpCNmOyqMs3KkmKVGTpqc4mJYWwDvL6i7HdrOoHZ1poTXNda3PCCfsMbu4mFCn/SbrHx5Slrs7ThWvhoQGkayTi9Ek8dkGd8S41LXkiPoZpG9bOGFEwgw1OJhgIp5M0cUQzniETVxp0xK8P39e1JgNXuw1kbJgnreX0+FKvMMWcRZ+q2KkRWK9Iv22D4EGhcJfuB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LZhZaypKHNJF/eqZyR3ZNfEQZOmE7kQMBojzzhMcfiiAH/z37aJO6wcvtx9oAXZC1GhU/9fe4nxzq4VaV/5tBN388x76zmPC8tVL40kLtA8n+l9ee9HnmE+QjjevELwjdLwOa8Bll12OL7y0Cm1nRLXzcMV8XkDCE9xEWdwqPbKrPA3nve X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: mm-unstable commit edd33b8807a1 ("mempolicy: migration attempt to match interleave nodes") added a second vma_iter search to do_mbind(), to determine the interleave index to be used in the MPOL_INTERLEAVE case. But sadly it added it just after the mmap_write_unlock(), leaving this new VMA search unprotected: and so syzbot reports suspicious RCU usage from lib/maple_tree.c:856. This could be fixed with an rcu_read_lock/unlock() pair (per Liam); but since we have been relying on the mmap_lock up to this point, it's slightly better to extend it over the new search too, for a well-defined result consistent with the policy this mbind() is establishing (rather than whatever might follow once the mmap_lock is dropped). Reported-by: syzbot+79fcba037b6df73756d3@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-mm/000000000000c05f1b0608657fde@google.com/ Fixes: edd33b8807a1 ("mempolicy: migration attempt to match interleave nodes") Signed-off-by: Hugh Dickins --- mm/mempolicy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 989293180eb6..5e472e6e0507 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1291,8 +1291,6 @@ static long do_mbind(unsigned long start, unsigned long len, } } - mmap_write_unlock(mm); - if (!err && !list_empty(&pagelist)) { /* Convert MPOL_DEFAULT's NULL to task or default policy */ if (!new) { @@ -1334,7 +1332,11 @@ static long do_mbind(unsigned long start, unsigned long len, mmpol.ilx -= page->index >> order; } } + } + mmap_write_unlock(mm); + + if (!err && !list_empty(&pagelist)) { nr_failed |= migrate_pages(&pagelist, alloc_migration_target_by_mpol, NULL, (unsigned long)&mmpol, MIGRATE_SYNC,