From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1DB74C79F82 for ; Tue, 8 Sep 2026 20:36:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C89310ED77; Tue, 8 Sep 2026 20:36:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="elG/WADn"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7869610ED77 for ; Tue, 8 Sep 2026 20:36:44 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F1A35601DE; Tue, 8 Sep 2026 20:36:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D842A1F00A3A; Tue, 8 Sep 2026 20:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788899803; bh=hyjLnquseXt3Sig0aykRcsZZ0Ak0XrxmINo3s38hEuE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=elG/WADnLNB7mOh29g9cQzG4hvN5oMtH36xxJcpzLhQl5lKsZa3I5ZolbSc/6Ddpg Ju1Lgtdsqn5I7T64pLHxxAVlaIIjfLO16scP193KxRisJTlPAFcfnhwXkClHjpWZ6P VIMJ4FfRNw2KqiK2u0vi8o86zdwKQows5ZwO/jYMiMxTpdu3rXo1XyUfgG1lVyWmUT cGKBVg8MJv9wQTFq3LHtdV0zU6devo3DeA57YYdFu5lFhmswbTa2plSjT26SEjAlHZ sO3q39/q7dCDkyjm/RMCMQUWnx316fHTxtGubScdcOKceeT5MioUgDFitf77BLNBBd MsqxttUCOTxeQ== From: sashiko-bot@kernel.org Subject: Re: [PATCH 04/39] mm/vma: ensure mmap_prepare doesn't set actions on a mergeable vma To: =?utf-8?b?TG9yZW56byBTdG9ha2VzIChBUk0p?= Cc: linux-s390@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-scsi@vger.kernel.org, "Christian Borntraeger" , "Heiko Carstens" , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, kvm@vger.kernel.org, selinux@vger.kernel.org, "Vasily Gorbik" , "Marc Zyngier" , kvmarm@lists.linux.dev, linux-perf-users@vger.kernel.org, "Oliver Upton" , "Alexander Gordeev" In-Reply-To: <20260908-b4-mmap-prepare-vma-flag-sanify-v1-4-dacf19cce22b@kernel.org> References: <20260908-b4-mmap-prepare-vma-flag-sanify-v1-0-dacf19cce22b@kernel.org> <20260908-b4-mmap-prepare-vma-flag-sanify-v1-4-dacf19cce22b@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 08 Sep 2026 20:36:42 +0000 Message-Id: <20260908203642.D842A1F00A3A@smtp.kernel.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Thank you for your contribution! Sashiko AI review found 1 potential issue(= s) to consider: Pre-existing issues: - [High] File reference leak in error paths of `call_mmap_prepare()` and `_= _compat_vma_mmap()` when validation fails after file replacement. -- commit c2c06e31f69acde90d013dcbd918472d63f3996c Author: Lorenzo Stoakes (ARM) mm/vma: ensure mmap_prepare doesn't set actions on a mergeable vma This commit adds validation to mmap_prepare_validate() to ensure that mmap actions are not set on VMAs that can be merged. It returns -EINVAL if such = an action is detected. > diff --git a/mm/vma.c b/mm/vma.c > index a24f04428580b..9e45fc83f74c6 100644 > --- a/mm/vma.c > +++ b/mm/vma.c > @@ -2794,6 +2794,15 @@ static int mmap_validate(unsigned long prev_start, > int mmap_prepare_validate(const struct vm_area_desc *prev_desc, > const struct vm_area_desc *desc) > { > + /* > + * It is not valid to execute mmap actions for VMAs which can be merged, > + * as any such merge would leave portions of the mapping incorrectly > + * unmapped. > + */ > + if (vma_flags_can_merge(&desc->vma_flags) && > + WARN_ON_ONCE(desc->action.type !=3D MMAP_NOTHING)) > + return -EINVAL; > + [Severity: High] This is a pre-existing issue, but by expanding the validation checks here, = does this increase the surface area of a struct file leak in the error paths of call_mmap_prepare() and __compat_vma_mmap()? If a driver's mmap_prepare hook replaces the mapping's backing file, it ret= urns a new file in desc->vm_file with an elevated refcount. If this newly added validation step fails, call_mmap_prepare() returns earl= y: mm/vma.c:call_mmap_prepare() { ... err =3D mmap_prepare_validate(&prev_desc, desc); if (err) return err; This skips the crucial handoff that ensures the cleanup code in abort_munma= p() will drop the reference to the new file: if (desc->vm_file !=3D map->file) { map->file_doesnt_need_get =3D true; map->file =3D desc->vm_file; } ... } Since map->file and map->file_doesnt_need_get are not updated on error, the caller's cleanup code ignores the new file reference, leading to a permanent leak of the struct file. The same early return leak applies to __compat_vma_mmap() in mm/util.c, whe= re desc is a stack variable and desc->vm_file is lost on error. Should these error paths handle fput() on desc->vm_file if it was replaced? > return mmap_validate(prev_desc->start, desc->start, > &prev_desc->vma_flags, &desc->vma_flags); > } --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260908-b4-mmap-pr= epare-vma-flag-sanify-v1-0-dacf19cce22b@kernel.org?part=3D4