From patchwork Fri Nov 1 16:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 13859593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2D12E6F06C for ; Fri, 1 Nov 2024 16:43:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DA9E6B0088; Fri, 1 Nov 2024 12:43:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78B886B0089; Fri, 1 Nov 2024 12:43:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 679926B008C; Fri, 1 Nov 2024 12:43:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4C8356B0088 for ; Fri, 1 Nov 2024 12:43:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D6EC4ABC05 for ; Fri, 1 Nov 2024 16:43:33 +0000 (UTC) X-FDA: 82738096266.26.4174C22 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf01.hostedemail.com (Postfix) with ESMTP id E48DF40019 for ; Fri, 1 Nov 2024 16:43:09 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=czU4tOPy; spf=pass (imf01.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730479196; h=from:from:sender: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:dkim-signature; bh=s2zJ3ZAsAPQ0E9uJzi8hgSgBj9U5Eh/vvFyC13/+d5w=; b=OTgebYvxeH+KsLAQp/CLvS6VBc1Tb4T6Q/igJ64ipaBhINJHyR0rODOeOwJh5XuGxb6aAq dORL/YrNQ4oT+KaPo9DZauBII2+kTC53qx8CJHYWqH6nfGUYYfYlvboSLShmLBISU3z9M9 6s7wCi7wG/8dF41AapE6NSRz9ijM4FI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=czU4tOPy; spf=pass (imf01.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730479196; a=rsa-sha256; cv=none; b=DLz90bVo4oN/lYZ7SOCdF85nQiIcn6Z5Wnkb6qmekOMPvlpqVI1mtnVpvb9Phw7XdGoGJe NTqlWe52nLMxBkkvUnDupNWtIYBh1F9OgZgtL1QAuPPT1bJGHSN1ukUzoxZbYaZlWABAcu Pt17C8svYsAMLzEF11MCnCpXSsqsaVY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=s2zJ3ZAsAPQ0E9uJzi8hgSgBj9U5Eh/vvFyC13/+d5w=; b=czU4tOPy9JPLZZs+bxemSdZzV5 /rpbQSDGQENcIJBnYPji0JLIMHGJzmvhFqnTK1JRE6WCUHznLbk8ETVJUw+hCSb9kvFQ+5x80idPV bQi67u3Fnc41GYhvnpoKVp5qVUc+kHXfTp3SdwXUTlBqHlcTLvMTtLFbI/LVhZVAyD+CkECEoSKXG Hmk7nI9g8d4OhUhZ7/0uR0o1VPaljl8ssXLel3QvOXM1A+rQQ+3LenzA89PdfAl2WOXpK3KzvQwJi Icdy2puxLfCgC/mhKhtRDGmsRSaUP1VeNViyZye0EVUWcKR1+X9koKub9NY/exwJyTDK6cX8Gy/gh bjhTsZyA==; Received: from [189.78.222.89] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uk7-000V2F-1g; Fri, 01 Nov 2024 17:43:23 +0100 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org, Stephen Rothwell , Nathan Chancellor Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Theodore Ts'o , =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 2/3] tmpfs: Fix type for sysfs' casefold attribute Date: Fri, 1 Nov 2024 13:42:50 -0300 Message-ID: <20241101164251.327884-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241101164251.327884-1-andrealmeid@igalia.com> References: <20241101164251.327884-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E48DF40019 X-Stat-Signature: h3dqsamy754rzutisww8rgptdfhdmpyd X-Rspam-User: X-HE-Tag: 1730479389-687895 X-HE-Meta: U2FsdGVkX1/+Axh0UhK/h0BTj1Ws/pWmjwaLlF088pbfdu95ybm8YnyAZht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R7lvQXoCSZXlygi6dOnJ9e3tuJCWz/ZS7kYZnT07r8Lo6KPimZ3La77GvIpgFxA+NtZviSHDHaSb9/2/LbhE5P+H5i1luCEnTf0UT3kax+Lzz6JCRuQTb7fjK4qifDSfubzm3Uf80Ka5Sep0nfmOmxcoAP7MJCtW8HqRH/ound8sZpyJoi0nIhWKiXIzS8OypkNHHgRGUPUE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: DEVICE_STRING_ATTR_RO should be only used by device drivers since it relies on `struct device` to use device_show_string() function. Using this with non device code led to a kCFI violation: > cat /sys/fs/tmpfs/features/casefold [ 70.558496] CFI failure at kobj_attr_show+0x2c/0x4c (target: device_show_string+0x0/0x38; expected type: 0xc527b809) Like the other filesystems, fix this by manually declaring the attribute using kobj_attribute() and writing a proper show() function. Also, leave macros for anyone that need to expand tmpfs sysfs' with more attributes. Fixes: 5132f08bd332 ("tmpfs: Expose filesystem features via sysfs") Reported-by: Nathan Chancellor Closes: https://lore.kernel.org/lkml/20241031051822.GA2947788@thelio-3990X/ Signed-off-by: André Almeida Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor --- mm/shmem.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b86f526a1cb1..6038e1d11987 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5548,13 +5548,38 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp); #if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) + +#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \ +{ \ + .attr = { .name = __stringify(_name), .mode = _mode }, \ + .show = _show, \ + .store = _store, \ +} + +#define TMPFS_ATTR_W(_name, _store) \ + static struct kobj_attribute tmpfs_attr_##_name = \ + __INIT_KOBJ_ATTR(_name, 0200, NULL, _store) + +#define TMPFS_ATTR_RW(_name, _show, _store) \ + static struct kobj_attribute tmpfs_attr_##_name = \ + __INIT_KOBJ_ATTR(_name, 0644, _show, _store) + +#define TMPFS_ATTR_RO(_name, _show) \ + static struct kobj_attribute tmpfs_attr_##_name = \ + __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) + #if IS_ENABLED(CONFIG_UNICODE) -static DEVICE_STRING_ATTR_RO(casefold, 0444, "supported"); +static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a, + char *buf) +{ + return sysfs_emit(buf, "supported\n"); +} +TMPFS_ATTR_RO(casefold, casefold_show); #endif static struct attribute *tmpfs_attributes[] = { #if IS_ENABLED(CONFIG_UNICODE) - &dev_attr_casefold.attr.attr, + &tmpfs_attr_casefold.attr, #endif NULL };