From nobody Sun Feb 8 17:23:33 2026 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 8070022CBF1 for ; Fri, 21 Mar 2025 19:49:17 +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=1742586559; cv=none; b=kVN1hgn0FB5YvYY1wMDEOQv9XRw+6jkqDL1Z9z4/QrbhnhYkVVSVuZHSIVPXvnC/cGy6m7JyielZ1IShJKxQ8pZJLh2uwMZ092PvUUTUTuG8gX64PH1inDVglDOh6MOf/rUzHqdSb5y2dLUx9GpD15ODOe0svBSXHCsCes3KQzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742586559; c=relaxed/simple; bh=+3PgL9e4pv3f6MCfYCBirhxZEuafw6SW80EvQcMyAKc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IyXWVjoU7/73w0qDgUvkRp6dLjILfIPNfpwCcxz6Y2359UpE2CMPiE0x2rFJE2xQtBD9Zo/zS3vk6KoTQtSBzMAUggaoXQUIt2vQZutkGfG626yQ7v3z3/E1deKqlNvSMiPfRLbdhR1pcjFir4gAm8TKgPXm+tqmCiuV+9hND5A= 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=Y0IkaepE; 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="Y0IkaepE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742586556; 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=sKu7K/L6aAgGXW9lSjE2s1++uZO1hHM3Uy8OChu+Qg0=; b=Y0IkaepEinUwV2mhwAcVUhyHJrpmGJoEZYK+5i04JjMmuAZB8A96KqpHc7LsnFm6F5JyPh oSRcC9gmuqlEpHkUMXfsjyD0JYT7JsCogIJhVDXEX2Pcg8yluy0+2mV1Y8fu1kVf06b2Dc DIDBII9KfaR7dTUmsJSzR9gqYv6suuM= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-mr2pRtKPM8emT4Slzv3T5w-1; Fri, 21 Mar 2025 15:49:14 -0400 X-MC-Unique: mr2pRtKPM8emT4Slzv3T5w-1 X-Mimecast-MFC-AGG-ID: mr2pRtKPM8emT4Slzv3T5w_1742586553 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ac287f284f8so171602666b.0 for ; Fri, 21 Mar 2025 12:49:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742586553; x=1743191353; 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=sKu7K/L6aAgGXW9lSjE2s1++uZO1hHM3Uy8OChu+Qg0=; b=YV/8kIpIYmMXqJcR4u95eGt+3VH2rAfAnd07XkPooxQg2f67v7p4jAQZeKsxdV0iAO LJg7pAl4z0J77HsgNlnOwiptXaCW69QkXI0J5dgoU0Si9xiqY1V5KD9MtDPW71cRJKpy bHw9z49bJ0UOjH+7xYDZIE6cyoO7+lWZ3gedHPZPFydlW/CbFyko4cON4pW48ObFgM/s L1mFCdBx2a48OJCrvK+3TPTbMmoWilCjBAAAuILDR6EwQr06+8wo2VEsFa9AiAHrCUO+ yd42MRNWbjeh/w1W/GIDlS0Q4Tvzeot141dTSSWAROFWg7IisAeUh8uEHZGilA+4ljwZ Cxaw== X-Forwarded-Encrypted: i=1; AJvYcCVbRlrZtS0ewJJKCu45MFVOSDSdh7o7PaPD9w5qrx/+oA4ajcCclCefCsYx+A0q9OLD0AfmMaupJNFliIY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxlq9Z01ondclgoTUradyPhSfmwfM61mQahP50gZwsIZlXMyOsi sZXX/avDEga5Saob2+BR9zZT4QMNWfYCEIglL1WxIluW2HxQRG4DyJIykWU34axDkai0QcK924/ nuchemJ5d0Mwft6IhpclU0Ncm69rPj2UcfEEN4upyH6AjLd4L0Gn/DA+9jwTF X-Gm-Gg: ASbGncsxZFPgjSx1VoLDoVp6ebAmSQovvytVOt+fhodPQ/X6QUeSHNn3BjDwi6hbuK6 TIWJzIU+NmmZetW23iGUEHCYfC1N7ABirnwPMDUs+GQIHOXAw2f0lr9qnhtSTy3LNAE8O33I1Vh v7BZxbFvJF3p2lwbhfpwrOVrbhe/8aRlAPp4duzgdBMAEHyqYCbCVvDHPUVHSA2y3yUco7zHvpG HTwLvyHUtDVE4JT+10xjRfgjjFBKp59VDo+qx06EIhq386ent9IJS/p0bdiNe3e7vUR6DxJf73Y NPAGeeR0dXrhTyw5/E3EOjnlqmKhDYKKJxdI/T+xXA== X-Received: by 2002:a17:906:c111:b0:ac3:17d3:eba1 with SMTP id a640c23a62f3a-ac3f20b04d9mr442075166b.9.1742586552984; Fri, 21 Mar 2025 12:49:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTcWGXZFGLvLNSApjQmfZCT80qQ9P9pa9GSOScyG8GRTDGLhsdL5pTYdHkyK/vdXMP8DguIA== X-Received: by 2002:a17:906:c111:b0:ac3:17d3:eba1 with SMTP id a640c23a62f3a-ac3f20b04d9mr442069766b.9.1742586552438; Fri, 21 Mar 2025 12:49:12 -0700 (PDT) Received: from [127.0.0.2] (ip-217-030-074-039.aim-net.cz. [217.30.74.39]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3ef8d3d38sm204412266b.39.2025.03.21.12.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Mar 2025 12:49:08 -0700 (PDT) From: Andrey Albershteyn X-Google-Original-From: Andrey Albershteyn Date: Fri, 21 Mar 2025 20:48:40 +0100 Subject: [PATCH v4 1/3] lsm: introduce new hooks for setting/getting inode fsxattr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250321-xattrat-syscall-v4-1-3e82e6fb3264@kernel.org> References: <20250321-xattrat-syscall-v4-0-3e82e6fb3264@kernel.org> In-Reply-To: <20250321-xattrat-syscall-v4-0-3e82e6fb3264@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" 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, Andrey Albershteyn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5252; i=aalbersh@kernel.org; h=from:subject:message-id; bh=+3PgL9e4pv3f6MCfYCBirhxZEuafw6SW80EvQcMyAKc=; b=owJ4nJvAy8zAJea2/JXEGuOHHIyn1ZIY0u8e2mDyP3iXzIzGyzyvts0333f0+anqT8z+Zx9d2 93ObXZz4Sv2jlIWBjEuBlkxRZZ10lpTk4qk8o8Y1MjDzGFlAhnCwMUpABPhyGL477dAsfnKfw52 rX2BV01C9n1oPuplfSp/RlXO7GNcbLIv0hkZrsSafJ+9Wc1t76Ty8u6CijnM972f5zPMuZ6mnXI teNdtXgA8MUuQ 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/ioctl.c | 7 ++++++- include/linux/lsm_hook_defs.h | 4 ++++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 638a36be31c14afc66a7fd6eb237d9545e8ad997..4434c97bc5dff5a3e8635e28745= cd99404ff353e 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -525,10 +525,15 @@ EXPORT_SYMBOL(fileattr_fill_flags); int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) { struct inode *inode =3D d_inode(dentry); + int error; =20 if (!inode->i_op->fileattr_get) return -ENOIOCTLCMD; =20 + error =3D security_inode_getfsxattr(inode, fa); + if (error) + return error; + return inode->i_op->fileattr_get(dentry, fa); } EXPORT_SYMBOL(vfs_fileattr_get); @@ -692,7 +697,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct de= ntry *dentry, fa->flags |=3D old_ma.flags & ~FS_COMMON_FL; } err =3D fileattr_set_prepare(inode, &old_ma, fa); - if (!err) + if (!err && !security_inode_setfsxattr(inode, fa)) err =3D inode->i_op->fileattr_set(idmap, dentry, fa); } inode_unlock(inode); diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index eb2937599cb029004f491012b3bf5a3d6d2731df..49e64d23e9049568af133bf3f30= ca719c9ec5f25 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -157,6 +157,10 @@ 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_setfsxattr, const struct inode *inode, + const struct fileattr *fa) +LSM_HOOK(int, 0, inode_getfsxattr, const struct inode *inode, + const 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 cbdba435b798660130779d6919388779edd41d54..dd58ace29c6e325ee49470596d0= abb6ecc38ba07 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -439,6 +439,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 *na= me); +int security_inode_setfsxattr(const struct inode *inode, + const struct fileattr *fa); +int security_inode_getfsxattr(const struct inode *inode, + const 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, @@ -1042,6 +1046,18 @@ static inline void security_inode_post_removexattr(s= truct dentry *dentry, const char *name) { } =20 +static inline int security_inode_setfsxattr(const struct inode *inode, + const struct fileattr *fa) +{ + return 0; +} + +static inline int security_inode_getfsxattr(const struct inode *inode, + const 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 09664e09fec9a1d502a23847aa2e87a6d19837db..d3b527f55ed52209d8e22c05adf= 278b164374d35 100644 --- a/security/security.c +++ b/security/security.c @@ -2617,6 +2617,38 @@ void security_inode_post_removexattr(struct dentry *= dentry, const char *name) call_void_hook(inode_post_removexattr, dentry, name); } =20 +/** + * security_inode_setfsxattr() - check if setting fsxattr is allowed + * @inode: inode to set filesystem extended attributes on + * @fa: extended attributes to set on the inode + * + * Called when setfsxattrat() syscall or FS_IOC_FSSETXATTR ioctl() is call= ed on + * inode + * + * Return: Returns 0 if permission is granted. + */ +int security_inode_setfsxattr(const struct inode *inode, + const struct fileattr *fa) +{ + return call_int_hook(inode_setfsxattr, inode, fa); +} + +/** + * security_inode_getfsxattr() - check if retrieving fsxattr is allowed + * @inode: inode to retrieve filesystem extended attributes from + * @fa: extended attributes to get + * + * Called when getfsxattrat() syscall or FS_IOC_FSGETXATTR ioctl() is call= ed on + * inode + * + * Return: Returns 0 if permission is granted. + */ +int security_inode_getfsxattr(const struct inode *inode, + const struct fileattr *fa) +{ + return call_int_hook(inode_getfsxattr, inode, fa); +} + /** * security_inode_need_killpriv() - Check if security_inode_killpriv() req= uired * @dentry: associated dentry --=20 2.47.2