From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADE5425B099 for ; Sat, 22 Aug 2026 05:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787375855; cv=none; b=ttDB3DRB8xQ4ANPcG+8MfURNQvEm7OzR0QKInLFStCBM0Xec4mqo+FZmLmLXxc8jPbKaAtfrO/8BXwbD/146eK+UHHq9FWW/c2Y1jvrnIHJqgEK9v6gCp+k3d290Z6XKMPGo9BE/JEc5zw0C27EbzQZahV9/VQSMtcqlo13J2ig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787375855; c=relaxed/simple; bh=JI/MWOMfUtza6fLR6APHNqEFtX5Ifei+2Obda2PjPdw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YVLZSQAFq2vX5lEvNdo8WTkiIYlyU/wencuLI5N9+5wTRtdtrMl+cywUCSsmle6kR980NyNvA9m2/Ys5e3m1AWppRGdMWsOO7Ae+iv0q8rhQMpma9cgUNilcFNcGw5BDWNo82oJHZebz++HFwQffe2TDzTK/yJza66kqFjQrBNU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cs.unc.edu; spf=pass smtp.mailfrom=cs.unc.edu; dkim=pass (2048-bit key) header.d=cs.unc.edu header.i=@cs.unc.edu header.b=XEbOLo6l; arc=none smtp.client-ip=209.85.128.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cs.unc.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cs.unc.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cs.unc.edu header.i=@cs.unc.edu header.b="XEbOLo6l" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-836c4474028so21415927b3.0 for ; Fri, 21 Aug 2026 22:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.unc.edu; s=google; t=1787375850; x=1787980650; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ObzK49S08DHWC6VkAKkzJZzxLTHEkWBeL1S/7Ye9ivQ=; b=XEbOLo6lX4ySSvv2NhTGgR+6VAmFME6J6psLa7GwKK7VXLnN4uR+xUMVgzNIrStmxW CYmqHFHA4Tpvv8+TvzINrWpSmLuRiYoMH/a8PZRCixjvKdP68/xqOW9LoCTjzVXW5aq5 tB5mIj25wTG7WnYML6siWEvDKEWRj2vBYsQ+pVnHsmFNlpB/IoDoZJmc9HZuCpEIFkWx utGwC64GlFCvovi9A6k9Z5DS2UtQ5gPsHi3eD7hxjwzAzVhnhAe4U+0p7AVq6PrVoCHV QRcpB/QONXG73HLGV8plgeBNJuHsWFe7XHomNpiMsEJux2HDV0aCPcDX+zmNZ36DMQYr SU/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787375850; x=1787980650; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ObzK49S08DHWC6VkAKkzJZzxLTHEkWBeL1S/7Ye9ivQ=; b=OY5NNmAsD3J7IxToib88uMAzMIxwyWc02hPXzRIcAjOoVzC8K08+SK+LaGfGq2lHA5 a4XJLxa/Uzbja4ou0/0JqOq9CFdOyirZhlHuvVmdJcpeakL1btS+ROJQ4t2HWlx6jjoy t86F3YHHn/eVuSK2DJTMxiWojGrRWjn7bgkJ9e8He/+77uNGgMGbYj4ZskxnpBIqO9hK 3S9YtmJVM3shYdwqy5aoA+TeI07jSBkO3ULOQOeC3kYgln+JuYoOxzeMZft9f4ffgXSr Y4XeUdc6NAVVbadMNp8G+DOLCJjeHgNhSzb7pMTx49UrIv4h7RNb2zmsd1pT0vOdUpy0 Xupg== X-Forwarded-Encrypted: i=1; AHgh+RqKKuhGbwoLnsdghkyN62zPoXnPBwjuG6qn9Btq4FTyKoZWrwupHztpNIUTjm5XYCait4JHYvb/4bfsXaU=@vger.kernel.org X-Gm-Message-State: AFuF++knRImRtpqKjY6mVV2pnJD+49NlNs5M31HPq6vJuRWYXSf2zjgp vjSyphbCyfDWU3U51UooV19fBx4J0pZek8sd6AEni8AqOeSL1+FQR45q9G2hjT1QjA== X-Gm-Gg: AR+sD13gwqaIljYHubP9c3cspw2VDJ2eCwG3BBzcc5xx779cun+1A2wzJD7PMkdgojv KX8XnhdPaYSnfe+KQl/2tIdIL9rbUB23UBKmzy+bSquUU2ODQI7MBmgsmTTAesnKHzeWVCRvTW9 tK0JPi89PA5Ynz8wt/EHCLU8lFPORpvMO1In7OaQLd0wG+6tZadwgbK8nldz1ykuBoXRC2CcehT 5D23As+F5UoIvPqcBZBd4UbrekEyvTLoVQnSRBRgG9xqsgbAy7GDmiNesTkO+ZkJ5z0U8XOkUF+ Zzlm40qbDTjUkAm1Y8Es9fI3L7/7z7IxtJq3LrjCNfKk1Ga0+KAmQLDanYtjTOTrdR7u0hGIs0w NoG5qn7OKV30S80fg9penAsz5qmSrJpuSPtdu6Tq5+54cs2Zc9CALqzlMUsQ51Oe84big3wD4W1 usWpw3XP3wv4cqrW7qVtPIKdBOBUttoFo0Udck6IMIg67XJ1WRsIW8lOPu2COIvoPWlG0bb5Xxd 4QcE9h32Sk= X-Received: by 2002:a05:690c:a08b:b0:82d:aa2e:2a66 with SMTP id 00721157ae682-849f67b0ac6mr35953267b3.23.1787375850496; Fri, 21 Aug 2026 22:17:30 -0700 (PDT) Received: from cobra01.cs.unc.edu (cobra01.cs.unc.edu. [152.2.130.143]) by smtp.gmail.com with ESMTPSA id 00721157ae682-84cac5ecceasm6504357b3.46.2026.08.21.22.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 22:17:29 -0700 (PDT) From: hengyul@cs.unc.edu To: chenyichong@uniontech.com, tj@kernel.org, dakr@kernel.org, gregkh@linuxfoundation.org Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2] kernfs: preserve security xattrs without allocating iattrs Date: Sat, 22 Aug 2026 01:17:05 -0400 Message-ID: <20260822051705.1761850-1-hengyul@cs.unc.edu> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hengyu Liang Commit d5e81a5650b5 ("kernfs: avoid iattr allocation in listxattr") made kernfs_iop_listxattr() return an empty list when the kernfs node has no allocated kernfs_iattrs. However, this also skips security xattr names provided by simple_xattr_list(). As of now, applications can retrieve the SELinux label of a sysfs file with getxattr(), but cannot do it through listxattr(). A similar issue happened before in commit b09e0fa4b4ea ("tmpfs: implement generic xattr support"). It was fixed by commit 8b0ba61df5a1c ("fs/xattr.c: fix simple_xattr_list to always include security.* xattrs"). Perhaps this recent commit needs a fix as well. The issue can be reproduced with a simple python program: python3 - <<'PY' import os path = "/sys/kernel/warn_count" print("getxattr:", os.getxattr(path, "security.selinux")) print("listxattr:", os.listxattr(path)) PY Before commit d5e81a5650b5 ("kernfs: avoid iattr allocation in listxattr"), the result is: getxattr: b'system_u:object_r:sysfs_t:s0\x00' listxattr: ['security.selinux'] After that commit, the result is: getxattr: b'system_u:object_r:sysfs_t:s0\x00' listxattr: [] This patch will keep listxattr() consistent with getxattr() when security xattrs are available. Fixes: d5e81a5650b5 ("kernfs: avoid iattr allocation in listxattr") Signed-off-by: Hengyu Liang Acked-by: Tejun Heo --- Changes in v2: - Remove an unnecessary line break. v1: https://lore.kernel.org/driver-core/20260821161221.1270292-1-hengyul@cs.unc.edu/ fs/kernfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 237dcdd73fc2..abb286bc3474 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -142,10 +142,8 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size) struct kernfs_iattrs *attrs; attrs = kernfs_iattrs_noalloc(kn); - if (!attrs) - return 0; - return simple_xattr_list(d_inode(dentry), &attrs->xattrs, buf, size); + return simple_xattr_list(d_inode(dentry), attrs ? &attrs->xattrs : NULL, buf, size); } static inline void set_default_inode_attr(struct inode *inode, umode_t mode) -- 2.53.0