From patchwork Wed Sep 25 01:40:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 1989112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XCzw86xdqz1xsM for ; Wed, 25 Sep 2024 11:41:12 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1stH1d-00018w-Mx; Wed, 25 Sep 2024 01:41:05 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1stH1c-00018i-E0 for kernel-team@lists.ubuntu.com; Wed, 25 Sep 2024 01:41:04 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 154173F335 for ; Wed, 25 Sep 2024 01:41:04 +0000 (UTC) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2dd60a85597so5712544a91.0 for ; Tue, 24 Sep 2024 18:41:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727228462; x=1727833262; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yllb8r5HnX5YHkBg4gbzsJamijgu3xxNkkDN/LWDQFk=; b=KTKMxEyiQIt5ITVKynBfIYZeS5HyMmi+y9bV4Rs5WnGl45UshxeMSYo3+kfYJRMK0X klr5X/pfCymxOigY/w7kpVwskxWfAQdRVBt6GH8X1JtxYVBkWIECbQIeIXEOPtkT4WfI c3GITvJ4vhJu0QwldMgjPRmumatmTa695fMnBaBqKXn9gveMyTLw5sqjo+JwK+j9xhJY a6O1Ziv0x1JnTT+pbgudgCyfItUw81453pMnNyPs4JQJUh9AwrCXQcpzX5tczXEMBlxM mxT9grMXjlKYkEIyEk/rPDS3/lYmJcjN0pcRsZjbw2saNVwPAcGRMk9WzuGtI6C3+kUn a+Tg== X-Gm-Message-State: AOJu0YwBL0myGdx8IJX2IYeTDBBKBlFfJpSoLzPybqfJErsICv8ug+xH u4RF7JbVScf4QvuPub9mJw6rIc/IKnZqoqeEtqr1rvUK0Wfbc2ECRArY/45YDVXmrt4DfR26SNp wJnJp56fN1jHp4wkWdNCfzQh2yUjXAJZWwQJc8EzxYlwv9qGfqNlai0uQZZ/EVYmbA2IpKoH96Z v5k1vumpEwrg== X-Received: by 2002:a17:90b:78d:b0:2d3:cd22:e66f with SMTP id 98e67ed59e1d1-2e06ae53a42mr1184426a91.9.1727228462419; Tue, 24 Sep 2024 18:41:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcVQWJsMg/C2ZN1tinYM51aaOri+paMZP4D8eTVS9q38NWc9+Qr9o/nQWe9g15S/VoBLarjg== X-Received: by 2002:a17:90b:78d:b0:2d3:cd22:e66f with SMTP id 98e67ed59e1d1-2e06ae53a42mr1184410a91.9.1727228461981; Tue, 24 Sep 2024 18:41:01 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:60ab:a189:1ef3:51ef]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e2f93e7sm221132a91.48.2024.09.24.18.41.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 18:41:01 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][N][PATCH 0/1] CVE-2024-43882 Date: Wed, 25 Sep 2024 10:40:28 +0900 Message-ID: <20240925014036.98880-1-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" [Impact] exec: Fix ToCToU between perm check and set-uid/gid usage When opening a file for exec via do_filp_open(), permission checking is done against the file's metadata at that moment, and on success, a file pointer is passed back. Much later in the execve() code path, the file metadata (specifically mode, uid, and gid) is used to determine if/how to set the uid and gid. However, those values may have changed since the permissions check, meaning the execution may gain unintended privileges. For example, if a file could change permissions from executable and not set-id: ---------x 1 root root 16048 Aug 7 13:16 target to set-id and non-executable: ---S------ 1 root root 16048 Aug 7 13:16 target it is possible to gain root privileges when execution should have been disallowed. While this race condition is rare in real-world scenarios, it has been observed (and proven exploitable) when package managers are updating the setuid bits of installed programs. Such files start with being world-executable but then are adjusted to be group-exec with a set-uid bit. For example, "chmod o-x,u+s target" makes "target" executable only by uid "root" and gid "cdrom", while also becoming setuid-root: -rwxr-xr-x 1 root cdrom 16048 Aug 7 13:16 target becomes: -rwsr-xr-- 1 root cdrom 16048 Aug 7 13:16 target But racing the chmod means users without group "cdrom" membership can get the permission to execute "target" just before the chmod, and when the chmod finishes, the exec reaches brpm_fill_uid(), and performs the setuid to root, violating the expressed authorization of "only cdrom group members can setuid to root". Re-check that we still have execute permissions in case the metadata has changed. It would be better to keep a copy from the perm-check time, but until we can do that refactoring, the least-bad option is to do a full inode_permission() call (under inode lock). It is understood that this is safe against dead-locks, but hardly optimal. [Fix] Noble: Clean cherry-pick Jammy: fixed via stable Focal: fixed via stable Bionic: fix sent to esm ML Xenial: fix sent to esm ML Trusty: won't fix [Test Case] Compile and boot tested [Where problems could occur] This fix addresses issues which is generic in nature, an issue with this fix would cause unexpected privilege escalation in rare race condition. Kees Cook (1): exec: Fix ToCToU between perm check and set-uid/gid usage fs/exec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) Acked-by: Mehmet Basaran Acked-by: Ivan Hu