From patchwork Fri Nov 1 01:37:40 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: 13858589 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 01324E67493 for ; Fri, 1 Nov 2024 01:38:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C7B96B009E; Thu, 31 Oct 2024 21:38:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 578566B009F; Thu, 31 Oct 2024 21:38:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CB8B6B00A5; Thu, 31 Oct 2024 21:38:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1FAA86B009E for ; Thu, 31 Oct 2024 21:38:12 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C514D41AA1 for ; Fri, 1 Nov 2024 01:38:11 +0000 (UTC) X-FDA: 82735814952.05.12E179B Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf10.hostedemail.com (Postfix) with ESMTP id D1CB8C0007 for ; Fri, 1 Nov 2024 01:37:57 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=rSsUgbSb; spf=pass (imf10.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=1730424874; 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=QXcbpwTTq6N974MuejeNHJ9xQ2vu2gRxnquK0VwfKiM=; b=sZA0GZBpGPaF//YWXOjQk/Hi/3zujw/3UW3hyUf3vlOS2wCklA2dyiHByYn0WTMEEam2P+ E1bz8oRpXBBaEBjQg7HYGZi0EQ/5vR40LGza+ucLVRwyMgA1TLXXr9yqZFMdCi6ZTOt2kb NWRYDLEmdybxuXUvShbFbIBevl42+hw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=rSsUgbSb; spf=pass (imf10.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=1730424874; a=rsa-sha256; cv=none; b=6I9w4dDgV7xXOj1mVg83HtfXx+lMiAfKklM7kf9iu7ECWvOqn3rOjn57R0+IG9doFlFLow irNEn8a+b1dCTq653Db84F0YhwjMZ0Jf0gvHqjPDEXKoM2VBONv45aiCK6HXRUra5tMOi1 MPHSRWgD56uD+70NPk6SK8F35r1SlM0= 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=QXcbpwTTq6N974MuejeNHJ9xQ2vu2gRxnquK0VwfKiM=; b=rSsUgbSbSkaGXZl2Nm0F3ZzIbh AsSs1pLZiilNWolJ0Ng/HkCRkTwnkQLW9ZdhOtdOBVFNuPI8HjhXpwBWRgrI5/SaVZat03DoIaYV4 uQrEZDBZ0N7tKgeKg3dtxC8JLbPmjfg2Fv5wL6LaCfy0TvL/Z6JszwJE7xsdjdsz9MQNEnlet/5iD cCuzVvwTvT6Vue9CJF/41cIz5pwqd7+GjifCk09VKnfRQOAorR8yfP8d+cHSnQmgBPutzEkAfJcrS IWQIM7j6PEHXGBBBtRCZ1oC7wpbHOqiNnawjK6epVIU1MKto1arXU5WH4jxQijvopmHnkJTscuu/l sFLOwJYw==; 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 1t6gbu-000G0m-VI; Fri, 01 Nov 2024 02:37:59 +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 2/3] tmpfs: Fix type for sysfs' casefold attribute Date: Thu, 31 Oct 2024 22:37:40 -0300 Message-ID: <20241101013741.295792-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241101013741.295792-1-andrealmeid@igalia.com> References: <20241101013741.295792-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D1CB8C0007 X-Stat-Signature: f91n457yson4jnqwog3xt6txp4s4g8xw X-Rspam-User: X-HE-Tag: 1730425077-490617 X-HE-Meta: U2FsdGVkX18biqN3P+PV8ZTxyS4ZlPxqg+B1Qh0qprJiNAKe5WRKRCRog19LzzFgxI4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2dDaec+7Mm25h7BQT9qbokOEWLZI1dyZDcQvN07d1pOANzRL1nASO/312oVESX3DKbxmPsWdPUEap69NnVqk6EMXMhJVaERV47GErpV/HcNkUMG3ifIMg2zfE47efhW27bpUORqjpwIzYxRUjJBLhy73X7ALEZXzy+Ppt4wgdHEBZO4UUtxb1XDWjKAIux1 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 (as seen in fs/btrfs/sysfs.c). 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 };