From patchwork Sun Oct 27 12:33:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13852519 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 2A219D116FB for ; Sun, 27 Oct 2024 12:34:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 808476B0082; Sun, 27 Oct 2024 08:34:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B87E6B0085; Sun, 27 Oct 2024 08:34:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67F8C6B0088; Sun, 27 Oct 2024 08:34:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 49ECA6B0082 for ; Sun, 27 Oct 2024 08:34:10 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 147FC41B99 for ; Sun, 27 Oct 2024 12:33:58 +0000 (UTC) X-FDA: 82719323820.25.02EF1F5 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf23.hostedemail.com (Postfix) with ESMTP id B20CA140017 for ; Sun, 27 Oct 2024 12:33:53 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dvTByAlh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730032406; a=rsa-sha256; cv=none; b=OoEp8RbCG54qQdRTqGQ8mHbemP3KncpqCqXl00RcDYkUXLCti3uBLTK0JrXKa5PoeC9f3P 7cXEut64lcWWPVNBvrto3yL8DsgrobWAFNeBF7uAAX9g8Vj38PoMwvjLcvQyUc1ASMIz/o JjGS3/mdoNND5sS5TeCn+tKXW6VuQl4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dvTByAlh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730032406; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=x7UJg7CptzscS9Fr/jO4VfwyEb8teWcA+vqkElKWHVg=; b=6Gs6DkP//en/DNV40BqcQly7LN31Askf9HA6XJw5BVag3sdnIn+0t8uA3V4du5pNSRwElT l5F081KXiseq37we57EFUr/vD3K/7lDm7OLFwoRqyLs+ORQ1rYk0SBS2+k9gZerNdh5MQD isaJ6PH4RuDZyMROJ+WP3HqrKwaV5u4= Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5cbb0900c86so2298683a12.0 for ; Sun, 27 Oct 2024 05:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730032446; x=1730637246; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x7UJg7CptzscS9Fr/jO4VfwyEb8teWcA+vqkElKWHVg=; b=dvTByAlhy6o/ouDHSwmoqb4/fNynVSxK18I33+xUZU+oIcbKm1qdBuw/f1Pwo/OZy3 4StXM1/VRNzT4haZ7hOqjTHTlYJVYpYa90/EHpq/7X88BnktI5feDAi4QsuKRhF57zrc CWaZZxEl1qkLh2b+DqDWubdLqnfEL2dEHjOATiZJB3f+X1sodOzJy/yh1mPQ0Qi+XJNL Ts2qLGYe4bJAijR1T0C5Cy/TM+9sF/FO2MjvEdjdwUno5vPDLY7Tc87x7eadCHWou3o+ 9eVFFCuKZCJA5J17MZLcKnBWefBza3s0TIO/4AqX89/i3dchSvXUEu0i0unjNZrZ59If QG/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730032446; x=1730637246; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x7UJg7CptzscS9Fr/jO4VfwyEb8teWcA+vqkElKWHVg=; b=RTDnyZVrP8x8b0JJNnpXImH7zHFKrTgz+HzVAGJEnjqb6QLt5/rp3l8BROqv/WTj8d fYExNJf8XMp8VjdiKKE6q0MpwPOk0Fsub6wY4GyFCJvn+wFbj4nmlw4rdKt18B5B4omA sbtZSCXP7aFHxaVJS0TA35re1ymF5YQko/32C5Gu4O5BmMU0dfv7toTK8V7aYNYFsOSA AY8ed9G8FgvVVGTV9LpxI6qQiSXZh2o+4EN/8ho7zOdytela6s6c995appY5DdJM7juH rEYkqJ1K+locXMacn0av8JzRh265EHyeXS+W9B+CHiE/8kQh5UvT3DqQhqzkFufNk0l8 RQ3w== X-Gm-Message-State: AOJu0YyX4u2nTez8TV7bwyr90Ne8B83oFMWhdk+Q29/ttaADthCBZR9S c8mgLdsjSGSKjVemTgs8V2plRtnLE0ch2iwXqHgf8Yf1jZDAbk2N X-Google-Smtp-Source: AGHT+IE9vgA8d0uwAw7Ke3lr7wIhuoX3KLIoobOll5sgPrOrrug9juMea6m7DhuV1YElfcjhZdywMQ== X-Received: by 2002:a17:907:6d0d:b0:a9a:147d:fe9c with SMTP id a640c23a62f3a-a9de61d5d59mr458423366b.43.1730032446143; Sun, 27 Oct 2024 05:34:06 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a086f6dsm272539466b.214.2024.10.27.05.34.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 Oct 2024 05:34:05 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org, vbabka@suse.cz, lorenzo.stoakes@oracle.com Cc: linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Jann Horn , stable@vger.kernel.org Subject: [PATCH hotfix 6.12 v2] mm/mlock: set the correct prev on failure Date: Sun, 27 Oct 2024 12:33:21 +0000 Message-Id: <20241027123321.19511-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Stat-Signature: 4a18hc15uadi6xig5qckkdqff3qzitda X-Rspamd-Queue-Id: B20CA140017 X-Rspamd-Server: rspam02 X-HE-Tag: 1730032433-61336 X-HE-Meta: U2FsdGVkX18jpStyJDESwNx8HX9Bw4Hc0pJCcfNBsdUNAWTuXWPpz9FOFZFdtzp3glUc+gOtQ3Tg5QMK0y4gRSYzXtD9fxi9HPUxG4HvQD+L3ezD7EsOdAE6ibNiwgbGm+fYeK4pHx9+AkSdui3zbwz7+vTy4CkK2mi0OqhN7PD0coy74VUEGYzbjlxw0E9+TilMndheLS6c8IbZab3IVZ+0/noljF3AXNS2DoXjdcedjLBQ4AJXR1S2LUZJ4Cttl4xtQ+6O+bU6g+NDVoGqAX+icjhAspqEY7Rbs3OyjS+cjAuQ4kmfGjMGty54QKeGu7BUVPZRPMWpvTOTr5ieo8ERCBAbKYpFWFwdtp3Mw+lx3hwSQlvRd90mYxcacbqCx9CxQjjdxZ4WrB4dMGnA85enGgmghohGQYyP4eKB8+ciSXC9hbll4WjMRVrsJG5turVNG8gpxBkvFq9KQ4Byy6wUjI6O97EBc5r3OxqNrazyE0z1CIz3O4CeK0xmvUkHwHA48hDdeaapjrLwdtpiPkXRaDb5mjj8+WAmd92E7MEPzpD1wzgC5rSVPvJ5K1XPzfDBRMBGPJ2bmgBppSp2VoemkOVrY6cjZ9MLEhUXGJiNEkeSg88KaOeHokhevBm4mijxTroNKHzXVFWbQHnn4LJQl1h0MZ7q8arpr1Wn82OctZF3xZL52UwBA+/GZtNzVSCPKqgzE8DP1bvT2vOuT3qBcVDu9+2OibwvSrp6ppdc5z7qjAXRTGUR00rpWA7wZC12pHojA0qKzrWoFMX/t7Qs27gAU15xMIaHbWBst8m/iR7+HBxCRIhWhBk7rooRt3WZflLQSZxHL7jjj1FWNq/pyOy4IvRT+KK3aMbpUER6oWij+DGlrcebSr0WGTL8DpG0ls9jIDiXDOjPFA+O+g0LiiBY6c5e0QGcLlBGHz9FYCYF3qzoX3bf/+IWyWJRN5z8o6wK2Qpb5cwv2th MDDQpIQJ DYHvZ3sUjpknr5jNjjfGrC2wTUoEm5LBXLwPm+fYwZ7NdpbcMZFQnQcQOJkeO4N1ORzMDnk6g8LLGFYIwvXL8BweSqV0r21G9elFJyHQdysMkDEmT90mfAek6bzKWyWrnUIS68ZoMeyAJWMBNjcOmFs92dYckHt2+veLwvddVuwxQX717WbF9MecrYMclgub8FUd8fDdZ9XVE7IHN8psp+UnjoGqQGBcSMCL+EGoBYEk2L6rhffFtLlf5bQaqvn2wIHQHdRNwqOgaeKuvJi+Aiu7igphF05XQtOC9NuDw+TDynhWtV/IEv3EQtKakUvvGu+voG1WIWQ5w/mvoVyaRf1A5Rm3zSM723r/WtusfWBLnYCQU3BD6X6Uxn8JnyZIEKR1JX4Q/94d35xC7h7BXlbNqf/PiwGBdTluDlHpzpo9S4+MqB7uE11D9LYdeXgfpsWLWMOMlg6GQF4urrcpMK2V5rPb+JArlQ6SOt3wMWf4ZQYSQWV7++FichiC1weQFLB75 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: After commit 94d7d9233951 ("mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al."), if vma_modify_flags() return error, the vma is set to an error code. This will lead to an invalid prev be returned. Generally this shouldn't matter as the caller should treat an error as indicating state is now invalidated, however unfortunately apply_mlockall_flags() does not check for errors and assumes that mlock_fixup() correctly maintains prev even if an error were to occur. This patch fixes that assumption. [lorenzo: provide a better fix and rephrase the log] Fixes: 94d7d9233951 ("mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al.") Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Lorenzo Stoakes CC: Vlastimil Babka CC: Jann Horn Cc: Reviewed-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- v2: rearrange the fix and change log per Lorenzo's suggestion add fix tag and cc stable --- mm/mlock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index e3e3dc2b2956..cde076fa7d5e 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -725,14 +725,17 @@ static int apply_mlockall_flags(int flags) } for_each_vma(vmi, vma) { + int error; vm_flags_t newflags; newflags = vma->vm_flags & ~VM_LOCKED_MASK; newflags |= to_add; - /* Ignore errors */ - mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end, - newflags); + error = mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end, + newflags); + /* Ignore errors, but prev needs fixing up. */ + if (error) + prev = vma; cond_resched(); } out: