From nobody Mon Dec 15 22:08:15 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 6CDE920D507 for ; Tue, 14 Jan 2025 21:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736891103; cv=none; b=qDYRpVLHYclp7aTusWqku2QPRkvqzUVr0UZJ2G/0FkWt0RiqGPkm+CMjfiO/4czs5+HHsNrgud2VOviPYTdAI423/Nrsx3Mw24bTpPKTB0ogvTNI+4Wym7BNh/KpH5XEwqYXw/PbmL0s/EyE+2jlZaRwSMK9DEMGr6Vl7pe7rtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736891103; c=relaxed/simple; bh=oV0Cv7k7TNZrKo+rio9MWcpQZ8LKPqoa0QDWQx35aLI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eZ5n3CWBtJ3lKLuuTujl6ClfToVHQDazdLzbSHFd1/dB5SmB7EYWeQ6asoKFg3VwAeYkUUZIsF0UHY4bb29lMg8Le+pJcfoksp40HLPIqden4ISoB5k7cEYjma/W74sGY1ivZP2gvunFJMDDg0TV2wvJsyI2cVgxH8go7Jp0TLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=sjKGH8zj; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="sjKGH8zj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1736891100; bh=oV0Cv7k7TNZrKo+rio9MWcpQZ8LKPqoa0QDWQx35aLI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sjKGH8zjegGG7hbjzEG4hDgTXfOkhoIjXSQBUX/VOoVEfRn9K+bIzdWJ0MI2VN4qt YiwrOsN4msiF1dBu5+NhxHxSDorwiEe6QdVL4LJ89UWDvvtJ15anYSM5YNUYpHqQ6H o/lf9k6iGUQN4+A4IwLpD9hSYQAlfMfvbpzuDSgQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 14 Jan 2025 22:44:58 +0100 Subject: [PATCH 1/2] devcoredump: Define 'struct bin_attribute' through macro 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: <20250114-sysfs-const-bin_attr-devcoredump-v1-1-fa93be30efae@weissschuh.net> References: <20250114-sysfs-const-bin_attr-devcoredump-v1-0-fa93be30efae@weissschuh.net> In-Reply-To: <20250114-sysfs-const-bin_attr-devcoredump-v1-0-fa93be30efae@weissschuh.net> To: Johannes Berg , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736891099; l=1002; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=oV0Cv7k7TNZrKo+rio9MWcpQZ8LKPqoa0QDWQx35aLI=; b=piioJhG1HC2JwF5SlQM5Doptu/Nncw8SWiUaMRGL3uvyoxjXwtJZGY4HN/9P2S5vgYM4Dcc6J bHW7cy0263NCPquGPdh7NryglvQl/kKIOvKv5nH68MXic9YIgi7TClf X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The macro saves some lines of code and simplifies the constification of the attribute. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/base/devcoredump.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c index c795edad1b969bc212dda5bd37578cb83118e850..13b3614c9ac911e704d3485b4f0= 370ce3b0afff6 100644 --- a/drivers/base/devcoredump.c +++ b/drivers/base/devcoredump.c @@ -132,12 +132,8 @@ static ssize_t devcd_data_write(struct file *filp, str= uct kobject *kobj, return count; } =20 -static struct bin_attribute devcd_attr_data =3D { - .attr =3D { .name =3D "data", .mode =3D S_IRUSR | S_IWUSR, }, - .size =3D 0, - .read =3D devcd_data_read, - .write =3D devcd_data_write, -}; +static struct bin_attribute devcd_attr_data =3D + __BIN_ATTR(data, 0600, devcd_data_read, devcd_data_write, 0); =20 static struct bin_attribute *devcd_dev_bin_attrs[] =3D { &devcd_attr_data, NULL, --=20 2.48.0 From nobody Mon Dec 15 22:08:15 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 32FCE20E6E7 for ; Tue, 14 Jan 2025 21:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736891103; cv=none; b=lljtRtQawcOm/5RWMp3xoS0MiksUPHEfI29gqz6l8u3afvG+ICqWwqUdoChgxvO6Wpl5D3cAHGkaGQv/hnTf4RkNfxdX0WNpdykKFvepvuJpiFbzCnAOE5+ckyfeHD+9sTKSd3BS5B0l9wkSEr2kaORF38qsxGom1pQjSzxHIWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736891103; c=relaxed/simple; bh=J3PorpSKUE2LRZVV0/3D4qTLAafm5md1YKEPp+HmGYo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jkI3C7sNXPHWYuxQMoec1xlUWAPgMjFMIewc50WPXa6zTfhbF+WP3/zqlBAQHT7OBRHj1Vkd/LxSaI+F5VcKYizyy2Pkl4VXHvF0wbu8z1MqrCfwg+8i+rCof1V7Igz97P9+RKeP7bNEMIbxq80kjhzJ5cougk7wUk6A/3H3qoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=kSecJanh; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="kSecJanh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1736891100; bh=J3PorpSKUE2LRZVV0/3D4qTLAafm5md1YKEPp+HmGYo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kSecJanh3rkE00Kxwt2GwLH/8HZYVOp80uifrlPNpCMhJMkZGITAyGD5oX7ysR3SL 1nsd8u14gBpHAgTCKfroz2sNJZIjPbtMcfiI5APCE67uEDlsNzvOFlaVwd0OlNdTBL P9uaqOCVjivCG0kZ1RomREK+E8jgHEnGEVzMZOpw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 14 Jan 2025 22:44:59 +0100 Subject: [PATCH 2/2] devcoredump: Constify 'struct bin_attribute' 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: <20250114-sysfs-const-bin_attr-devcoredump-v1-2-fa93be30efae@weissschuh.net> References: <20250114-sysfs-const-bin_attr-devcoredump-v1-0-fa93be30efae@weissschuh.net> In-Reply-To: <20250114-sysfs-const-bin_attr-devcoredump-v1-0-fa93be30efae@weissschuh.net> To: Johannes Berg , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736891099; l=1945; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=J3PorpSKUE2LRZVV0/3D4qTLAafm5md1YKEPp+HmGYo=; b=95d7PlauQrdUoxmE8Os56uNPeUl2a3SA05nksMbhzuwgITZq+IjKCrv1LlNrhXt1xr73OCpKO V9q5I1glL7PC2njhAKG/N387bH5W4yGrSJ+3tadybgz/nuJ2OC1gdC6 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/base/devcoredump.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c index 13b3614c9ac911e704d3485b4f0370ce3b0afff6..031b0d2ec924184f3b868fbaa37= 90b7f98bc9e2c 100644 --- a/drivers/base/devcoredump.c +++ b/drivers/base/devcoredump.c @@ -106,7 +106,7 @@ static void devcd_del(struct work_struct *wk) } =20 static ssize_t devcd_data_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t offset, size_t count) { struct device *dev =3D kobj_to_dev(kobj); @@ -116,7 +116,7 @@ static ssize_t devcd_data_read(struct file *filp, struc= t kobject *kobj, } =20 static ssize_t devcd_data_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t offset, size_t count) { struct device *dev =3D kobj_to_dev(kobj); @@ -132,15 +132,15 @@ static ssize_t devcd_data_write(struct file *filp, st= ruct kobject *kobj, return count; } =20 -static struct bin_attribute devcd_attr_data =3D +static const struct bin_attribute devcd_attr_data =3D __BIN_ATTR(data, 0600, devcd_data_read, devcd_data_write, 0); =20 -static struct bin_attribute *devcd_dev_bin_attrs[] =3D { +static const struct bin_attribute *const devcd_dev_bin_attrs[] =3D { &devcd_attr_data, NULL, }; =20 static const struct attribute_group devcd_dev_group =3D { - .bin_attrs =3D devcd_dev_bin_attrs, + .bin_attrs_new =3D devcd_dev_bin_attrs, }; =20 static const struct attribute_group *devcd_dev_groups[] =3D { --=20 2.48.0