Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1941530rdb; Mon, 9 Oct 2023 07:44:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFETTt4wdjm8hpHiwQxodf873oFbbP5ZYccOk5BwjWDsJXhutWmIJBi+w1cgCrxrOtipWIG X-Received: by 2002:a17:903:1c1:b0:1c7:61a1:9695 with SMTP id e1-20020a17090301c100b001c761a19695mr14040197plh.20.1696862642945; Mon, 09 Oct 2023 07:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696862642; cv=none; d=google.com; s=arc-20160816; b=dpJZ2pUztTZExsrancvnJhORvM+RmXj90lHZBbzWbZGueRR8QH80zVQrt+aa0L/54i 29zSFdMOyhGGgRiabbjSwQo/W79E9AStFufEyvaPS+HWAX1af/oxoWS9cnISfdEpKfKN 7AeE79smEvGX/ahi3Dktd2+xwvj0ehpGkEsiGLZR4QmA4J8UdgomZ2VBXzfJzWmvt7+z w3VAWnU2lfyZjqZaNGpioHV5qiQWvEZU6QhqulNo1L8JdWChvdXoGupokuvm2tz1nPwz F65Mmx7E0g0kprYohc7cvfyXGO0zSpHiHtVQ4elXtsU2kQpLQz46ZErTaVFoS/IzNAie 9aPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fp8oeCHkXnZ8PoMfDAewrEbM2hzEMNE0S/oIdHJqQHU=; fh=tFO1AYymf86ey/KBx3xeOspWWkYnYg0Z9DpvnRcao6U=; b=SX+Ybl7fMhv017YyaLhBfZTzuprvPTKmTpQD06DvLjsDvLldLY3eAM3GS6vQH+9zoa YdVK7d8PYIWmteGeBh13Hmamyvv0xWdP9W8SAF939ruc/BKkw7HoIUWwHlyrPxxNHrYP I28ZlQykkA/Ux/AEaHFCPpI5e0GTcSPeGGdjIPzFTRlMHuxgCw3SRjkRxMr2yUvLiQnC umlyuPt95gVh+jeFUSKuK8gOyL+jfVW9B8QqvwaeXogSuT4+wsgLtQKNC12YCs24SuBJ VITFgBSKelkwn0QbN/G1agGD0losvW/MB5bccpx5kUrWpFxpwNR0scYZKBtJ+zj2iwNQ 69GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=KbxDPeGE; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t13-20020a170902e84d00b001c74d84425bsi10332145plg.31.2023.10.09.07.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 07:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=KbxDPeGE; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D1F9C80C6150; Mon, 9 Oct 2023 07:43:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234088AbjJIOns (ORCPT + 99 others); Mon, 9 Oct 2023 10:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232912AbjJIOnr (ORCPT ); Mon, 9 Oct 2023 10:43:47 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044868F for ; Mon, 9 Oct 2023 07:43:46 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40684f53d11so46501495e9.1 for ; Mon, 09 Oct 2023 07:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1696862624; x=1697467424; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fp8oeCHkXnZ8PoMfDAewrEbM2hzEMNE0S/oIdHJqQHU=; b=KbxDPeGE97rYRx2p2uojWNblc2edIjGQvh6H+zrw1U1rxHuEof+uIBTSkR12YdxAiB X9SomFgE7mFfxZGPcceWMBF3bq7JRYKUZtKtUMzYN8ERVgjDROBIFbzXxFWT65x32yfT JW6wzh7ZXdGWp8HpVbpf/a1W/TxfP4khssEggkONfPMiWB84061fdO/VmGBYaCWlVJDf DP7X0phi+dkLUbsQxeHtmjh5Fn0VS1CqXs924qC4iBkfhk+oAO5r+etf9HmZrHOWg7u4 Hpv0o385C3vti9wN39OkgV/M1I2qJ97shKuSlnSmWhXoQDP6daoFw2NO7zebnrccvXgn xnsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696862624; x=1697467424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fp8oeCHkXnZ8PoMfDAewrEbM2hzEMNE0S/oIdHJqQHU=; b=HpoC1efT6jwb+dit7z7llxM4m+0WepwkNeicLy9STPOazJjTTe0ko5p5rnX2nRKszJ m8a4MW+SELx3vgtETmCjf91XbrEMaTNpcm/jLRiRDU/MEI96DQXYw92uoM4V6GT0n7QH yqkhW+kOQp/ZdxlKyyJf34f0spQOOCCxZhI23YbvpulT5POPlltMU98ZzOUiznPOOkKK XPDiyEs0kqhtC+zBMETCVi8CFVZvx9rdXCY3VA64S+CEtq4YEa6TBqIC2kp9L2vYC30I 2Zc7/9stul1sYpzbjL3BrZe0S0XAqsg3+axq+sP01970iMzF4GuSw7NMBinay5ifRvi6 KqrQ== X-Gm-Message-State: AOJu0YxMB/6JNO80N1bkazCgjDI2aQsH0Y5S4wF70D2BpfE5LEoJmZ1+ Cjdz4V6Je76S0shgxUDE1FGb3g== X-Received: by 2002:a7b:c419:0:b0:402:f5c4:2e5a with SMTP id k25-20020a7bc419000000b00402f5c42e5amr13938953wmi.37.1696862624328; Mon, 09 Oct 2023 07:43:44 -0700 (PDT) Received: from heron.intern.cm-ag (p200300dc6f49a600529a4cfffe3dd983.dip0.t-ipconnect.de. [2003:dc:6f49:a600:529a:4cff:fe3d:d983]) by smtp.gmail.com with ESMTPSA id n26-20020a05600c3b9a00b004068def185asm11433113wms.28.2023.10.09.07.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 07:43:44 -0700 (PDT) From: Max Kellermann To: Xiubo Li , Ilya Dryomov , Jeff Layton , Jan Kara , Dave Kleikamp Cc: Max Kellermann , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, jfs-discussion@lists.sourceforge.net Subject: [PATCH v2] fs/{posix_acl,ext2,jfs,ceph}: apply umask if ACL support is disabled Date: Mon, 9 Oct 2023 16:43:39 +0200 Message-Id: <20231009144340.418904-1-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <69dda7be-d7c8-401f-89f3-7a5ca5550e2f@oracle.com> References: <69dda7be-d7c8-401f-89f3-7a5ca5550e2f@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 09 Oct 2023 07:44:00 -0700 (PDT) X-Spam-Level: ** One important implementation detail of the posix_acl_create() function is that it applies the umask to the "mode" parameter. If CONFIG_FS_POSIX_ACL is disabled, this detail is missing and the umask may not get applied. This patch adds the missing code to posix_acl_create() and to three filesystems that omit the posix_acl_create() call if their individual ACL support is disabled (CONFIG_EXT2_FS_POSIX_ACL, CONFIG_JFS_POSIX_ACL, CONFIG_CEPH_FS_POSIX_ACL). If posix_acl_create() never gets called, the umask needs to be applied anyway. This bug used to be exploitable easily with O_TMPFILE (see https://bugzilla.kernel.org/show_bug.cgi?id=203625) but that part was fixed by commit ac6800e279a2 ("fs: Add missing umask strip in vfs_tmpfile") last year. The bug may not be reachable by userspace anymore, but since it is apparently still necessary to apply the umask again in posix_acl_create(), there is no reason to assume it's not necessary with ACL support is disabled. Signed-off-by: Max Kellermann --- fs/ceph/super.h | 6 ++++++ fs/ext2/acl.h | 6 ++++++ fs/jfs/jfs_acl.h | 6 ++++++ include/linux/posix_acl.h | 1 + 4 files changed, 19 insertions(+) diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 51c7f2b14f6f..58349639bd57 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -1194,6 +1194,12 @@ static inline void ceph_forget_all_cached_acls(struct inode *inode) static inline int ceph_pre_init_acls(struct inode *dir, umode_t *mode, struct ceph_acl_sec_ctx *as_ctx) { + /* usually, the umask is applied by posix_acl_create(), but if + * ACL support is disabled at compile time, we need to do it + * here, because posix_acl_create() will never be called + */ + *mode &= ~current_umask(); + return 0; } static inline void ceph_init_inode_acls(struct inode *inode, diff --git a/fs/ext2/acl.h b/fs/ext2/acl.h index 4a8443a2b8ec..0ecaa9c20c0c 100644 --- a/fs/ext2/acl.h +++ b/fs/ext2/acl.h @@ -67,6 +67,12 @@ extern int ext2_init_acl (struct inode *, struct inode *); static inline int ext2_init_acl (struct inode *inode, struct inode *dir) { + /* usually, the umask is applied by posix_acl_create(), but if + * ACL support is disabled at compile time, we need to do it + * here, because posix_acl_create() will never be called + */ + inode->i_mode &= ~current_umask(); + return 0; } #endif diff --git a/fs/jfs/jfs_acl.h b/fs/jfs/jfs_acl.h index f892e54d0fcd..64a05e663a45 100644 --- a/fs/jfs/jfs_acl.h +++ b/fs/jfs/jfs_acl.h @@ -17,6 +17,12 @@ int jfs_init_acl(tid_t, struct inode *, struct inode *); static inline int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir) { + /* usually, the umask is applied by posix_acl_create(), but if + * ACL support is disabled at compile time, we need to do it + * here, because posix_acl_create() will never be called + */ + inode->i_mode &= ~current_umask(); + return 0; } diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h index 0e65b3d634d9..54bc9b1061ca 100644 --- a/include/linux/posix_acl.h +++ b/include/linux/posix_acl.h @@ -128,6 +128,7 @@ static inline void cache_no_acl(struct inode *inode) static inline int posix_acl_create(struct inode *inode, umode_t *mode, struct posix_acl **default_acl, struct posix_acl **acl) { + *mode &= ~current_umask(); *default_acl = *acl = NULL; return 0; } -- 2.39.2