Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1970194rwe; Fri, 2 Sep 2022 06:47:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR5W6+Mh1PsfXe0QeZlMcejSbbHb2+Np6/9daMh+88xBozRYiEL7WyvYfqVb0oAoz2eH/rDQ X-Received: by 2002:a17:90b:3e86:b0:1f5:2b4f:7460 with SMTP id rj6-20020a17090b3e8600b001f52b4f7460mr5021022pjb.97.1662126423465; Fri, 02 Sep 2022 06:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126423; cv=none; d=google.com; s=arc-20160816; b=SiV4FkXlV6YCj2/a9jeKOktsoiXGX4oGThJKMavbOsU5w4dOpL5qbh64lNnma2z2eE U0Od7mWN/rHRtfwm2EuFizteBmOxo6d/Nf7iyiFgWepbbrABjakTIgCvbh/No1gv0KC3 EGetjEXkr+Apnn1m+4Vojp8DRNCQWwgoQT7iVGuh7KTuGNTihR0gipk898jg277X63ks 4wiD9V1mc8ChSTYCR+a+mWhj/FVcsR2QLkhAt6DtbS/uGx4OSzQTqXVaYcTjMCpRYzsE zSGp5a3HtOBve6shPyKMkshL/p/nHpWMjm7GUfZYyPRCnKfbLqQC6mYS14CWMT+g4tRS zEog== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4nw+413AAbyNOAAe8jBCVziOZ/udDKkwngA5qoBCq/E=; b=pVbZwQPvMqBcOxcB0y5HXC4+nujqjHRlOL6oKXto/yuLWayJGBU+mq1gpNq9QwX6no 36kWQmcViyKKlKE3ItJgRqb+qyGPzxEEa9i5FiFtLARAMpY/YEqaIybtvMZY0aDIHKkh MA/TtTeeyQ8i8YqIukyKQCHBYf5oD0TXtaCPJgLHOrPkChsF9Xf8a2WMj2mbIHy5vCuw MLuBEIjb1xUdyGkXj+MkWcRfpwIs+06rD0p29RR/GKDYOOu771CBYr642YquncnBwzt0 w5soHq62uNNwdDw8l7sns7MIpyom3Gr1A2sfMKFyp8smgaCuCmLod4Lgka/r0uQLWJ/8 dAZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YYpIWZPN; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om4-20020a17090b3a8400b001fe4d6dbd9dsi4604087pjb.163.2022.09.02.06.46.49; Fri, 02 Sep 2022 06:47:03 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=YYpIWZPN; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237087AbiIBMkS (ORCPT + 99 others); Fri, 2 Sep 2022 08:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237109AbiIBMiZ (ORCPT ); Fri, 2 Sep 2022 08:38:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A24E14D14; Fri, 2 Sep 2022 05:29:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 24C776212E; Fri, 2 Sep 2022 12:28:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 278F4C433D6; Fri, 2 Sep 2022 12:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121705; bh=lcyJE0m0RvTkV7SS8mQ29O1jB6tQLac53XR7vc6SdT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YYpIWZPNERB6jbq8oUW3LTfxZvSsb0IpWvMvqUfelKyw/0VaTp2Lf1WVOEz+BJBbF flu5ZglV1kHaH84sGn678mc3XrBcgzCh4+CcxLeT2hK0HqVQpzhvCq117QM0EstQQJ 6gmhazqm4Fn0WZycPSdogt3ZapseUDB6pCYUeQqk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Filipe Manana , Goldwyn Rodrigues , David Sterba Subject: [PATCH 5.4 39/77] btrfs: check if root is readonly while setting security xattr Date: Fri, 2 Sep 2022 14:18:48 +0200 Message-Id: <20220902121404.952779080@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121403.569927325@linuxfoundation.org> References: <20220902121403.569927325@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLACK 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 From: Goldwyn Rodrigues commit b51111271b0352aa596c5ae8faf06939e91b3b68 upstream. For a filesystem which has btrfs read-only property set to true, all write operations including xattr should be denied. However, security xattr can still be changed even if btrfs ro property is true. This happens because xattr_permission() does not have any restrictions on security.*, system.* and in some cases trusted.* from VFS and the decision is left to the underlying filesystem. See comments in xattr_permission() for more details. This patch checks if the root is read-only before performing the set xattr operation. Testcase: DEV=/dev/vdb MNT=/mnt mkfs.btrfs -f $DEV mount $DEV $MNT echo "file one" > $MNT/f1 setfattr -n "security.one" -v 2 $MNT/f1 btrfs property set /mnt ro true setfattr -n "security.one" -v 1 $MNT/f1 umount $MNT CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Qu Wenruo Reviewed-by: Filipe Manana Signed-off-by: Goldwyn Rodrigues Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/xattr.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c @@ -387,6 +387,9 @@ static int btrfs_xattr_handler_set(const const char *name, const void *buffer, size_t size, int flags) { + if (btrfs_root_readonly(BTRFS_I(inode)->root)) + return -EROFS; + name = xattr_full_name(handler, name); return btrfs_setxattr_trans(inode, name, buffer, size, flags); }