From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 84E682951DE for ; Mon, 12 May 2025 13:25:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747056337; cv=none; b=oVpi6A0eULY+cHSDxEgNihlOJC9I/QAjmZFKWpbGPNl4a6L90rgOi0W6iGFQLfjYwB4XbEcozzpJH0NWWGTB/8NhmniozhTAdJTFnI3ZHedUuZK1Bjs0Ud2lC+2zt7Pl/Ngy6dqQtEC9tvHS16cVZ4bCXdVrKzhgVeZ6G+poVPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747056337; c=relaxed/simple; bh=EE7KRw5zpeu2NPRaS4FGB5R9ATQBOE/dVjbJqb/tg1Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T15wRwmu5oWf9/muLddpAKIjxjVUe2YE/7YH7Pn0w/xREsom91DVjyCi+t+d1bbk89DSiV1utcmber4ikzFjxPF2O5Jsl0FO8jsmwn1ZE43h5zVge84L/dikkKiy8hAcGIpko28cZGGU5CgoUXPtHWA2tUVOf+GgL7eoOairq5M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gvKuRFCT; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gvKuRFCT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747056332; 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=9zdzYFU67QL/yrQjWemjUC5iC/W3DMR3kub6Fg2erUY=; b=gvKuRFCTL3mIF1yNIPHpVxth285gXaq0iY3y/psfEzIVdPnAhqlev8J42z+bfBRRgGKkrH eywZLe3UXF28pmuNP/hyzZJzsG1MD6fy1GzztFpcVnFEBxFb+RyPFnQprWjhxNfVDK7n5u ot41tnUO9R/l4Vkg1DRuHL8wDzfbiPY= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-8o57TbWDPs6ibB7o_o1Xig-1; Mon, 12 May 2025 09:25:31 -0400 X-MC-Unique: 8o57TbWDPs6ibB7o_o1Xig-1 X-Mimecast-MFC-AGG-ID: 8o57TbWDPs6ibB7o_o1Xig_1747056330 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5f638cacf63so3635615a12.1 for ; Mon, 12 May 2025 06:25:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747056330; x=1747661130; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9zdzYFU67QL/yrQjWemjUC5iC/W3DMR3kub6Fg2erUY=; b=aFo7I0w6RKht7X8C5W/f+aCe5Mr/w1nIrnrWOKYZC2Zmg1Sit5SW72F9TRCyLv3mdE Jr20bqMGRzT6r4Z+P25TZjn+C1wuYL358YnJyZ4DTXFlCSpLDpvA+RP4uQ4Cgx2Mcy3t Fczm5nNaArn2gK2wu2fJbLhgr/np92WrkATQMvQO0V0BdE8IBUzdoqizfzKfoFjDVcgo Y+Veso2LWG6Wy911ysyFFq+Cgf5r46nAqSLU/ajeD9UUJXG8KtWps9KUecdFx+hRNvpJ opctm2JD+SqKEouy2B1k6V5LxtK3jQ5eCq6jXyKBLCZag/bmP8WtJR6MixcZHBlfjMUm A+Gw== X-Forwarded-Encrypted: i=1; AJvYcCWNg89XWLviOjIRwuxIc9KyLtjbU7Km5Swq8chKIv+gm8Wlxa8WChPLAt64M0jWt2ADe6pFhjXIwg==@vger.kernel.org X-Gm-Message-State: AOJu0YwtWLwmDNpn5zr0r0VWs9i0rtZEKYfXwf0MCBPXLcIX+vf2WPbz /c7P+VlQYST6e9nndAE+p8uoz8ywJpPZ/fmCQZmC2W0Mk4Qr6NooLEMqF2MsIVPpC+qM8tcqeR+ zDYTrdVaCKowMzCbaPyvocTC2CQrlATC1eFFaNNPk+cVrs8QdHUEVnU4= X-Gm-Gg: ASbGnctwjqu5x2FpPIfJXsjkj5Z7gX8m0eScQREE+3hMXwXNl94QJr0yIzIY94j5Z1A 6qXzgiQmJeRqkpoAnEW1qRtkwM3xRpU1CldC/A1LXQpxFYdbCtYkvB7E01Vx87QMkhs2IpCNpLg oiOIa3TbeM1KGO8R34NVgJxwma4TXDi+Qj+hIogy5dmm3I5FuDLtIoZ9jmQkoeCed0Oz9BM5ocx /JxDkylab35K1cgZf9NToIOi3Fc0iOcHLP6hjV/OHXIX+QkJO+xZyIQxhg+MkcKBtmYjLlAmaz4 mjos+YhockE2dPCGqhuHzbcLztc= X-Received: by 2002:a05:6402:210b:b0:5fd:ef5d:cfc4 with SMTP id 4fb4d7f45d1cf-5fdef5ddcacmr4241588a12.32.1747056330218; Mon, 12 May 2025 06:25:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgyFRWpHIHyxLqyb63eiEMcoz6JMXZOSqP4STcTWiczoMtX+J1IqNwFoMZx8exSweSW5WJFw== X-Received: by 2002:a05:6402:210b:b0:5fd:ef5d:cfc4 with SMTP id 4fb4d7f45d1cf-5fdef5ddcacmr4241498a12.32.1747056329623; Mon, 12 May 2025 06:25:29 -0700 (PDT) Received: from [127.0.0.1] (109-92-26-237.static.isp.telekom.rs. [109.92.26.237]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5fc9cc2633bsm5788360a12.20.2025.05.12.06.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 May 2025 06:25:29 -0700 (PDT) From: Andrey Albershteyn X-Google-Original-From: Andrey Albershteyn Date: Mon, 12 May 2025 15:25:13 +0200 Subject: [PATCH v5 2/7] lsm: introduce new hooks for setting/getting inode fsxattr Precedence: bulk X-Mailing-List: ecryptfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250512-xattrat-syscall-v5-2-4cd6821e8ff7@kernel.org> References: <20250512-xattrat-syscall-v5-0-4cd6821e8ff7@kernel.org> In-Reply-To: <20250512-xattrat-syscall-v5-0-4cd6821e8ff7@kernel.org> To: Richard Henderson , Matt Turner , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Chris Zankel , Max Filippov , Alexander Viro , Christian Brauner , Jan Kara , =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , Arnd Bergmann , =?utf-8?q?Pali_Roh=C3=A1r?= , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek , Tyler Hicks , Miklos Szeredi , Amir Goldstein Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, selinux@vger.kernel.org, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, Andrey Albershteyn X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5194; i=aalbersh@kernel.org; h=from:subject:message-id; bh=EE7KRw5zpeu2NPRaS4FGB5R9ATQBOE/dVjbJqb/tg1Q=; b=owJ4nJvAy8zAJea2/JXEGuOHHIyn1ZIYMhS/7eU/HpORlvbTw9rAc0Wgxfs73zR6Gn4y9my8L JR99sWJf4odpSwMYlwMsmKKLOuktaYmFUnlHzGokYeZw8oEMoSBi1MAJmI0m5Hhm6pb0gp73Yfh UZFnGpJLNFtbJ1621OupmDl/5aTt21rlGP47OGdl1BlEf2TxmvE1S5hl8oaj839ZcxyJ9dxwwts 2fQ4rALHeR6U= X-Developer-Key: i=aalbersh@kernel.org; a=openpgp; fpr=AE1B2A9562721A6FC4307C1F46A7EA18AC33E108 Introduce new hooks for setting and getting filesystem extended attributes on inode (FS_IOC_FSGETXATTR). Cc: selinux@vger.kernel.org Cc: Paul Moore Signed-off-by: Andrey Albershteyn --- fs/file_attr.c | 19 ++++++++++++++++--- include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/fs/file_attr.c b/fs/file_attr.c index 2910b7047721..be62d97cc444 100644 --- a/fs/file_attr.c +++ b/fs/file_attr.c @@ -76,10 +76,15 @@ EXPORT_SYMBOL(fileattr_fill_flags); int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) { struct inode *inode = d_inode(dentry); + int error; if (!inode->i_op->fileattr_get) return -ENOIOCTLCMD; + error = security_inode_file_getattr(dentry, fa); + if (error) + return error; + return inode->i_op->fileattr_get(dentry, fa); } EXPORT_SYMBOL(vfs_fileattr_get); @@ -242,12 +247,20 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, } else { fa->flags |= old_ma.flags & ~FS_COMMON_FL; } + err = fileattr_set_prepare(inode, &old_ma, fa); - if (!err) - err = inode->i_op->fileattr_set(idmap, dentry, fa); + if (err) + goto out; + err = security_inode_file_setattr(dentry, fa); + if (err) + goto out; + err = inode->i_op->fileattr_set(idmap, dentry, fa); + if (err) + goto out; } + +out: inode_unlock(inode); - return err; } EXPORT_SYMBOL(vfs_fileattr_set); diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index bf3bbac4e02a..9600a4350e79 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -157,6 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, struct dentry *dentry, const char *name) LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa) +LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa) LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry, diff --git a/include/linux/security.h b/include/linux/security.h index cc9b54d95d22..d2da2f654345 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -451,6 +451,10 @@ int security_inode_listxattr(struct dentry *dentry); int security_inode_removexattr(struct mnt_idmap *idmap, struct dentry *dentry, const char *name); void security_inode_post_removexattr(struct dentry *dentry, const char *name); +int security_inode_file_setattr(struct dentry *dentry, + struct fileattr *fa); +int security_inode_file_getattr(struct dentry *dentry, + struct fileattr *fa); int security_inode_need_killpriv(struct dentry *dentry); int security_inode_killpriv(struct mnt_idmap *idmap, struct dentry *dentry); int security_inode_getsecurity(struct mnt_idmap *idmap, @@ -1053,6 +1057,18 @@ static inline void security_inode_post_removexattr(struct dentry *dentry, const char *name) { } +static inline int security_inode_file_setattr(struct dentry *dentry, + struct fileattr *fa) +{ + return 0; +} + +static inline int security_inode_file_getattr(struct dentry *dentry, + struct fileattr *fa) +{ + return 0; +} + static inline int security_inode_need_killpriv(struct dentry *dentry) { return cap_inode_need_killpriv(dentry); diff --git a/security/security.c b/security/security.c index fb57e8fddd91..09c891e6027d 100644 --- a/security/security.c +++ b/security/security.c @@ -2622,6 +2622,36 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name) call_void_hook(inode_post_removexattr, dentry, name); } +/** + * security_inode_file_setattr() - check if setting fsxattr is allowed + * @dentry: file to set filesystem extended attributes on + * @fa: extended attributes to set on the inode + * + * Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on + * inode + * + * Return: Returns 0 if permission is granted. + */ +int security_inode_file_setattr(struct dentry *dentry, struct fileattr *fa) +{ + return call_int_hook(inode_file_setattr, dentry, fa); +} + +/** + * security_inode_file_getattr() - check if retrieving fsxattr is allowed + * @dentry: file to retrieve filesystem extended attributes from + * @fa: extended attributes to get + * + * Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on + * inode + * + * Return: Returns 0 if permission is granted. + */ +int security_inode_file_getattr(struct dentry *dentry, struct fileattr *fa) +{ + return call_int_hook(inode_file_getattr, dentry, fa); +} + /** * security_inode_need_killpriv() - Check if security_inode_killpriv() required * @dentry: associated dentry -- 2.47.2