Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1409660pxv; Fri, 25 Jun 2021 12:15:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI62oGU2p7PhM8BNc+OQcXQzfPxif2jwC7IrR4aNaGw6iq7blUrm6UIMO018f0RwyTXtu1 X-Received: by 2002:a05:6602:2433:: with SMTP id g19mr10045151iob.100.1624648525986; Fri, 25 Jun 2021 12:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624648525; cv=none; d=google.com; s=arc-20160816; b=i4rb27iALB8u4wmQMqrTdVfyUkAAEJS38OVBIUWanQSdeURNlQHbbwV4B5FYWLNmmg +eMWdxLr8zJ3//RE9HjfvM5W0IosWeGoN8CvnZFT+A0XTgtjtVstQLKsThxFJ0FHojmG 1IfZUhFlRd8q48ScQhSOc+L5VC9dN9VVDPg2/sYD0XeqJE2hSfeRQzNc7pkbArijI5fN 2oPsIiamrHd3A13d5JhCrXw86BPREATiIqVawDbjQcmZ0gYp3tiIUO7LiSKkGHuqdksH ghFlQzVO0jW7WZ27XXmiMTIFxAztwwkMkpAd0xo3oJxcXoY9JEW2ooWbsD23AnFeLCj8 RSdQ== 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=mR7BPB7xUD+lHwXPAeAm7p/vk/MlEKiHZItlpMSs9TU=; b=TOfSnWMHDUD7l5ble4BpnLUpMwZvvTo8c9kZ6UuOJo3E4i4oKNvmWONsnaxDJRq8F8 7mWZ4bXwMZV4fi81I1TvDbnUQgxOqizYi5NYW+f27cTSaV4sJPo6N+ytcCP8zTjPumbS FaPjHfqzxigSRs+ysjgMOGnV26MhzVojXxqjgKQjSkHEKGUzLija/jv/MLWiwpFm2JTL asbNmiZqmfnuIoI99qjHtuj1It2Bi8OXyY8s8hQhGT5ZciGlP+UtvIDBgfTuzxyZl92k O70oq+DN0xzPqloTrtFxxNtfTdMQ7ifv4ZJkuhumNFRZazupNSHCEVV0OEu18mWKlGcK TmlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I/95zXYu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si1450316ili.68.2021.06.25.12.15.13; Fri, 25 Jun 2021 12:15:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I/95zXYu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbhFYTPM (ORCPT + 99 others); Fri, 25 Jun 2021 15:15:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37340 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbhFYTPK (ORCPT ); Fri, 25 Jun 2021 15:15:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624648369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mR7BPB7xUD+lHwXPAeAm7p/vk/MlEKiHZItlpMSs9TU=; b=I/95zXYusctGLN/1Ybyovt6N2qR9GFpSLA69UEZn7LQjOY5di5xdgeP57FvAC8SmL0C6HQ rT1mR5f0K+zo1wzp3VrJpe0qkE4f4tOok3/isGVu0vQQ9DWKe1p9PLzrML6zNeaR5sIigT VPEAxZRDE/TUEQ4+QpVxnCM4yg1yqNE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-598-p5mUJjNIM6yt1lWjb4paHA-1; Fri, 25 Jun 2021 15:12:45 -0400 X-MC-Unique: p5mUJjNIM6yt1lWjb4paHA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67BF41835AC8; Fri, 25 Jun 2021 19:12:44 +0000 (UTC) Received: from horse.redhat.com (ovpn-114-161.rdu2.redhat.com [10.10.114.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC5B15D6A8; Fri, 25 Jun 2021 19:12:40 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 850BF223D99; Fri, 25 Jun 2021 15:12:40 -0400 (EDT) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: virtio-fs@redhat.com, dwalsh@redhat.com, dgilbert@redhat.com, berrange@redhat.com, vgoyal@redhat.com Subject: [PATCH 1/1] xattr: Allow user.* xattr on symlink/special files with CAP_SYS_RESOURCE Date: Fri, 25 Jun 2021 15:12:29 -0400 Message-Id: <20210625191229.1752531-2-vgoyal@redhat.com> In-Reply-To: <20210625191229.1752531-1-vgoyal@redhat.com> References: <20210625191229.1752531-1-vgoyal@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As of now user.* xattrs are allowed only on regular files and directories. And in case of directories if sticky bit is set, then it is allowed only if caller is owner or has CAP_FOWNER. "man xattr" suggests that primary reason behind this restrcition is that users can set unlimited amount of "user.*" xattrs on symlinks and special files and bypass quota checks. Following is from man page. "These differences would allow users to consume filesystem resources in a way not controllable by disk quotas for group or world writable spe‐ cial files and directories" Capability CAP_SYS_RESOURCE allows for overriding disk quota limits. If being able to bypass quota is primary reason behind these restrictions, can we relax these restrictions if caller has CAP_SYS_RESOURCE. Signed-off-by: Vivek Goyal --- fs/xattr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/xattr.c b/fs/xattr.c index 5c8c5175b385..10bb918029dd 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -124,7 +124,8 @@ xattr_permission(struct user_namespace *mnt_userns, struct inode *inode, * extended attributes. For sticky directories, only the owner and * privileged users can write attributes. */ - if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) { + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && + !capable(CAP_SYS_RESOURCE)) { if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) return (mask & MAY_WRITE) ? -EPERM : -ENODATA; if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) && -- 2.25.4