From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E08EF4611CF; Tue, 16 Jun 2026 17:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781630293; cv=none; b=TsB70iuANoha/+jXMiEI9C/onkh+5nWtE2t6eDbqrco1O+9FFSUIU0UyD5lNzDeByGvUX8vWYnLGZ/s+QV/IyMBepOv+3cOqmi7GpratKE9tzIHiKtGZFIYqaNwNdzPP7dL8zSha/Q4u6MpQ9YbRuzIPgH4OL25LXQCDlwfz05w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781630293; c=relaxed/simple; bh=xRPQG/FbekZ9bErcNE4OX3TlHRtfn0foNqr9CthwCTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bBRO8gBjQv6Nnayu5ckxJ8HIrHWeHPIdROu08WXZzq//18L3Rg/t3GDTR5Q1UbOg0KeXP0cmihJYTMxaHQSYDfCZgoWTD/9UID4pLFJI8iaBm/h9oquwW9HiPGS2lvF/R6GMuGCfcYC5yp0nN7xyPXZXml6zBuz7z6LC9WCgnh4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FV4dWsgL; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FV4dWsgL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E3D61F000E9; Tue, 16 Jun 2026 17:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781630291; bh=IdmgfLszT6E7RHtJEHtaI+hsR/P/GHLoKHBjtzYcuuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FV4dWsgL4iNxXCVedK5ZLz8Q54r3e3Op45w6MleHJVbWgsnGXoOUu11rWMArCxxjE 6sf5mKOX/QU3dfsikpMsaSKcQLMd5Ng0RIirZbod1YuCq1vdUKKgm58iDVOcO2GGHk sbgRzmiuYlMw95NjtVyVpVUXoGO7oCzH6N4Z5R4c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Pratyush Yadav (Google)" , Pasha Tatashin , Jeff Xu , Baolin Wang , Brendan Jackman , Greg Thelen , Hugh Dickins , Kees Cook , "David Hildenbrand (Arm)" , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 414/452] memfd: deny writeable mappings when implying SEAL_WRITE Date: Tue, 16 Jun 2026 20:30:41 +0530 Message-ID: <20260616145138.533241777@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145117.796205997@linuxfoundation.org> References: <20260616145117.796205997@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Pratyush Yadav (Google)" [ Upstream commit 3b041514cb6eae45869b020f743c14d983363222 ] When SEAL_EXEC is added, SEAL_WRITE is implied to make W^X. But the implied seal is set after the check that makes sure the memfd can not have any writable mappings. This means one can use SEAL_EXEC to apply SEAL_WRITE while having writeable mappings. This breaks the contract that SEAL_WRITE provides and can be used by an attacker to pass a memfd that appears to be write sealed but can still be modified arbitrarily. Fix this by adding the implied seals before the call for mapping_deny_writable() is done. Link: https://lore.kernel.org/20260505133922.797635-1-pratyush@kernel.org Fixes: c4f75bc8bd6b ("mm/memfd: add write seals when apply SEAL_EXEC to executable memfd") Signed-off-by: Pratyush Yadav (Google) Reviewed-by: Pasha Tatashin Acked-by: Jeff Xu Cc: Baolin Wang Cc: Brendan Jackman Cc: Greg Thelen Cc: Hugh Dickins Cc: Kees Cook Cc: "David Hildenbrand (Arm)" Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- mm/memfd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/mm/memfd.c +++ b/mm/memfd.c @@ -210,6 +210,12 @@ static int memfd_add_seals(struct file * goto unlock; } + /* + * SEAL_EXEC implies SEAL_WRITE, making W^X from the start. + */ + if (seals & F_SEAL_EXEC && inode->i_mode & 0111) + seals |= F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_FUTURE_WRITE; + if ((seals & F_SEAL_WRITE) && !(*file_seals & F_SEAL_WRITE)) { error = mapping_deny_writable(file->f_mapping); if (error) @@ -222,12 +228,6 @@ static int memfd_add_seals(struct file * } } - /* - * SEAL_EXEC implys SEAL_WRITE, making W^X from the start. - */ - if (seals & F_SEAL_EXEC && inode->i_mode & 0111) - seals |= F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_FUTURE_WRITE; - *file_seals |= seals; error = 0;