Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6589922rwb; Mon, 5 Dec 2022 14:48:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf6U7RzFNE+XcabNvogeneJ4tq6F26RbAttlPFwbvfTTj18B59sM1OiY32Di7pVKzl2jSyMk X-Received: by 2002:a05:6402:2b8a:b0:46b:2979:7397 with SMTP id fj10-20020a0564022b8a00b0046b29797397mr34270428edb.332.1670280503059; Mon, 05 Dec 2022 14:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670280503; cv=none; d=google.com; s=arc-20160816; b=moJY01CSnihTzFlptHbFhwM6QsoNh4YnkJxEAjNzuYODYlTBDPKEGrJlxtdUCRAb4H uNk2GQjRURLDCfo4lpDAJspdJHcVVM4zj0kw+uKH3lA4SXXaZi9dArDgGTnO6AyNtJf9 c7rlUbGaN5W78HNoQoegP7dkFiNH/bOvDg18Wdk04qtMZZxae5FrATGoz8lUBHsg/bq5 FkF9+8N+ckhg3aoQvkxSLPHB0z0gPzl/WPPrqkhRtdiGI7jJTYd45S0sGWRVNjzxUFjO BBc/EhXagvnZ2HiAyQatoc/W7gNZAWZYdDKfVoj3bvsibynzyYVeCdDgGFu+JspkuYr+ QL+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xt4Ng4f7DzUWlFKte3qMSDvwTEhhgAP9/m+VDXnbEuM=; b=D7p5Muawmqes4bmSe9nZbpMzdPiCtoTxVY4ywdpIWbdtGMd1n/xwAJhR23mTsEt3oi fC9aP9yAn84mp5Q413COs4OrWzRR2NLRuzTiFgvNDFG9bnhCA+4U/zdkFwgCBgouljRx S+/8u1sy60FwHbLLH+5Sjo+viDCuS+71F6dM1JDUo2mDDtJeFWvZbRecKpubYqt/Nh3h DHIW3LKuicCmLuwPlVg6lQfNWte3qs5sPY2IBlavLJ2E5At6Tm+iIM50Ph8sFO/5uQUt B4UFp7564KLGe1xhdAHgMFEZK1WpljV1AZXL5Ocl6rI7sNFYJPkYxFnYW2yKJaVf1eh4 pmPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SotciC8k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f25-20020a056402151900b00461d9b46883si510504edw.519.2022.12.05.14.48.03; Mon, 05 Dec 2022 14:48:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SotciC8k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232399AbiLEWX2 (ORCPT + 79 others); Mon, 5 Dec 2022 17:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233119AbiLEWXW (ORCPT ); Mon, 5 Dec 2022 17:23:22 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3E54E55 for ; Mon, 5 Dec 2022 14:23:21 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id z144so4288704iof.3 for ; Mon, 05 Dec 2022 14:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xt4Ng4f7DzUWlFKte3qMSDvwTEhhgAP9/m+VDXnbEuM=; b=SotciC8kaLwKhrcdt91+e4nXCnaYRZ41wQ3VF1dEHvlyCu+GVPavsc/0Fk4GH5L0wG UTqxf2iosDU041ewIB36QI1qFLbPx8VVDEH5z1FVBxq1Q95/oAyF9zm6aR0FvEIsPHrJ Lb0IvRmHGADn7QQ3avIlJ3xtkUloyDPwFNeJwBujXeUT51oeT0InhaqG8MSGSr69k24o KYCqJ2nyj/aIsdNptDVeEhSg6rRzZ+aPLf+x5p+imJw+ZBoiIxFHglgzxVjb75KtPfiq brRseJHlBy0IO3bHnkTyer1DV2QPdcDJOwOGB8TTSFClCXFy2s6OSOHn15gEXyM2qxgf HMNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xt4Ng4f7DzUWlFKte3qMSDvwTEhhgAP9/m+VDXnbEuM=; b=a9RFcv2gyqYOVCl7DRTtqzzltZLE1UhH/m/juHk2oxg7tVKTxoXn5trp/mHLi+u/Zv 2q/yvoiRbvzWv98X2fC0E0d/NUk/yVxM4ydjQgoHFadqaHHzz6yEsbrudlirGoI6sFw1 sXcwLBaNOhZCX8LHr3AgR3TVfCjbJZTLv+017v2TkMaiAYXDoPF681hX6QhTO9czTJcD VHuvKfm4cD6EAQ5cYBcHy4MLapAoGA/HpPhoNbSKII4bcjyVzsh7SSjXnfiEPxf+8s9q pRof376Y/iHD6dFQTuZLBxnVyEdKr7reAkZJl97iPZDcdR5JFVtqRwM6gCoJM/b8z1gl x1bw== X-Gm-Message-State: ANoB5pndhR9ADSm70pOZNzY3kZYzcUgpzhqRaYgxnl7cTG0oatjDpyLC sJsm3VC6UMQp0Wff2NY5SszMNc5+vJGosfr8znCnSQ== X-Received: by 2002:a5d:8f84:0:b0:6d9:56fc:ef25 with SMTP id l4-20020a5d8f84000000b006d956fcef25mr29352334iol.56.1670279000948; Mon, 05 Dec 2022 14:23:20 -0800 (PST) MIME-Version: 1.0 References: <20221205192304.1957418-1-Liam.Howlett@oracle.com> <20221205123250.3fc552d96fcca5dc58be8443@linux-foundation.org> In-Reply-To: From: Jann Horn Date: Mon, 5 Dec 2022 23:22:44 +0100 Message-ID: Subject: Re: [PATCH v2] mmap: Fix do_brk_flags() modifying obviously incorrect VMAs To: Vlastimil Babka Cc: Andrew Morton , Liam Howlett , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Yu Zhao , Jason Donenfeld , Matthew Wilcox , SeongJae Park Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 5, 2022 at 11:13 PM Vlastimil Babka wrote: > On 12/5/22 22:55, Jann Horn wrote: > > On Mon, Dec 5, 2022 at 9:32 PM Andrew Morton wrote: > >> On Mon, 5 Dec 2022 19:23:17 +0000 Liam Howlett wrote: > >> > Add more sanity checks to the VMA that do_brk_flags() will expand. > >> > Ensure the VMA matches basic merge requirements within the function > >> > before calling can_vma_merge_after(). > >> > >> I't unclear what's actually being fixed here. > >> > >> Why do you feel we need the above changes? > >> > >> > Drop the duplicate checks from vm_brk_flags() since they will be > >> > enforced later. > >> > > >> > Fixes: 2e7ce7d354f2 ("mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()") > >> > >> Fixes in what way? Removing the duplicate checks? > > > > The old code would expand file VMAs on brk(), which is functionally > > wrong and also dangerous in terms of locking because the brk() path > > isn't designed for file VMAs and therefore doesn't lock the file > > mapping. Checking can_vma_merge_after() ensures that new anonymous > > VMAs can't be merged into file VMAs. > > > > See https://lore.kernel.org/linux-mm/CAG48ez1tJZTOjS_FjRZhvtDA-STFmdw8PEizPDwMGFd_ui0Nrw@mail.gmail.com/ > > . > > I guess the point is that if we fix it still within 6.1, we don't have to > devise how exactly this is exploitable, Yeah, that was sort of my thinking. > but due to the insufficient locking > it most likely is, right? To be honest, I don't really know how bad this is - pretty much the only thing we're doing here is to change the VMA end. I don't know if that messes up the address_space's interval tree or something? I have no clue how that data structure looks.