From nobody Sun Dec 14 13:49:50 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 462471FF1D0; Wed, 11 Dec 2024 17:54:42 +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=1733939685; cv=none; b=PVk3TalRFqxVj4SB9dNJNYt5F4wF3mfLwsVtO4zS04wC59sKOU4lQecgm8AaTCzdc3aMhsXRCoSHdk5BGgo2VklaeZ/Ze0mvB3auoUp/DwyPJJUwzdjd6YojXM0gpRUOImQcelE5eD1rjm/HYgzl/UeUzHm9TfTRnp0XFu+aIN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733939685; c=relaxed/simple; bh=xV6zJcNk00t9KvA7nCk23QmQDDzZHzdCO7WdqX+VHho=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aGM0rxr3niyxLNMNeSQGUXWcf1/nwtwv+Y0LwbIIyFgSBQSNjqWkDHZHdmO41lAWLz6MlVeQzmfMKBebwaI3eqz+tuCSNbpOW2paZIUL1efJBq9DuSSxM2Kh9s3fGYKZ5fb9mOA14APxllcqaxgSz0PxjW6bp0Wv4vf036xRLmY= 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=REZlKwLL; 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="REZlKwLL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733939680; bh=xV6zJcNk00t9KvA7nCk23QmQDDzZHzdCO7WdqX+VHho=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=REZlKwLLl+o4neplV3J+cyp6ZxDal9gSj3poOhkb7sxin/PdAHJKjcjnQIagO3lZD DbOUFlvSWdPNPvWZOo+EcM755L529HNPDR56ByvfMTMs0k44MzG+1Hv1bNpRkeflmh O77lguE2/DE6j6e/RnmCQTC2DVnbvhbnl/paQaNs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Dec 2024 18:54:39 +0100 Subject: [PATCH 1/5] s390/crypto/cpacf: 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: <20241211-sysfs-const-bin_attr-s390-v1-1-be01f66bfcf7@weissschuh.net> References: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> In-Reply-To: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Vineeth Vijayan , Peter Oberparleiter , Harald Freudenberger , Holger Dengler Cc: linux-s390@vger.kernel.org, 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=1733939680; l=3086; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=xV6zJcNk00t9KvA7nCk23QmQDDzZHzdCO7WdqX+VHho=; b=W38JfBzSN15hiDaBEBR5fuiLjhMuSpVPM1vylF1AfEbLH0PpsvYnBHBByMHGtmxNBS+S6s4ck TJBRFJoospmAM4H+nYsq+U73febAs0XTmb4ZmatfyKLGEclYwXpQQzt 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 Reviewed-by: Holger Dengler Tested-by: Finn Callies --- arch/s390/kernel/cpacf.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/s390/kernel/cpacf.c b/arch/s390/kernel/cpacf.c index c8575dbc890d64a5fcdcbd7a1a18215e2158c6e3..4b9b34f95d729806d416279b93c= cb5a20e4406a7 100644 --- a/arch/s390/kernel/cpacf.c +++ b/arch/s390/kernel/cpacf.c @@ -14,7 +14,7 @@ #define CPACF_QUERY(name, instruction) \ static ssize_t name##_query_raw_read(struct file *fp, \ struct kobject *kobj, \ - struct bin_attribute *attr, \ + const struct bin_attribute *attr, \ char *buf, loff_t offs, \ size_t count) \ { \ @@ -24,7 +24,7 @@ static ssize_t name##_query_raw_read(struct file *fp, \ return -EOPNOTSUPP; \ return memory_read_from_buffer(buf, count, &offs, &mask, sizeof(mask)); \ } \ -static BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t)) +static const BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t)) =20 CPACF_QUERY(km, KM); CPACF_QUERY(kmc, KMC); @@ -40,20 +40,20 @@ CPACF_QUERY(prno, PRNO); CPACF_QUERY(kma, KMA); CPACF_QUERY(kdsa, KDSA); =20 -#define CPACF_QAI(name, instruction) \ -static ssize_t name##_query_auth_info_raw_read( \ - struct file *fp, struct kobject *kobj, \ - struct bin_attribute *attr, char *buf, loff_t offs, \ - size_t count) \ -{ \ - cpacf_qai_t qai; \ - \ - if (!cpacf_qai(CPACF_##instruction, &qai)) \ - return -EOPNOTSUPP; \ - return memory_read_from_buffer(buf, count, &offs, &qai, \ - sizeof(qai)); \ -} \ -static BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t)) +#define CPACF_QAI(name, instruction) \ +static ssize_t name##_query_auth_info_raw_read( \ + struct file *fp, struct kobject *kobj, \ + const struct bin_attribute *attr, char *buf, loff_t offs, \ + size_t count) \ +{ \ + cpacf_qai_t qai; \ + \ + if (!cpacf_qai(CPACF_##instruction, &qai)) \ + return -EOPNOTSUPP; \ + return memory_read_from_buffer(buf, count, &offs, &qai, \ + sizeof(qai)); \ +} \ +static const BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t)) =20 CPACF_QAI(km, KM); CPACF_QAI(kmc, KMC); @@ -69,7 +69,7 @@ CPACF_QAI(prno, PRNO); CPACF_QAI(kma, KMA); CPACF_QAI(kdsa, KDSA); =20 -static struct bin_attribute *cpacf_attrs[] =3D { +static const struct bin_attribute *const cpacf_attrs[] =3D { &bin_attr_km_query_raw, &bin_attr_kmc_query_raw, &bin_attr_kimd_query_raw, @@ -101,7 +101,7 @@ static struct bin_attribute *cpacf_attrs[] =3D { =20 static const struct attribute_group cpacf_attr_grp =3D { .name =3D "cpacf", - .bin_attrs =3D cpacf_attrs, + .bin_attrs_new =3D cpacf_attrs, }; =20 static int __init cpacf_init(void) --=20 2.47.1 From nobody Sun Dec 14 13:49:50 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 AF7F51FF5E3; Wed, 11 Dec 2024 17:54:42 +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=1733939684; cv=none; b=phX9o+U6gwE6fb7yElyXQgke0TNo/a5EVJeUsLwo2/ceKCRJ9dIMjSrGlCV1gPgZX4spHhCb9YDaM4PuofZX1f1d5EIuCiRrE6ckCIZ4Ri7072y9CQb+4v0jHJTkGwZXuKVfDBJjpvxkldkjwjDXDZRK6EXYCC6RDeEoUnIh2pY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733939684; c=relaxed/simple; bh=12hHO6niZJCGhDppSxFeOOejXGKMBYthJ3BtK3jvRTk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=h2VKDNBp2lVYmFOGdRLXNtWV8fqw5BEDkpvG82kLUxe0fIuHr+yV/jiN3BTIZSbt5hdD2/0QVIRg/sy/ufbwGldxRkaURMANaUD1YiGKkhlKecY/F/8wIiAljsaAYnUrkMVXxsGebm8ke/C4QYVEg5hpZy7W96DKyWscR4S7PW0= 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=TzEUFM+P; 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="TzEUFM+P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733939680; bh=12hHO6niZJCGhDppSxFeOOejXGKMBYthJ3BtK3jvRTk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TzEUFM+P4aeZJONYMcELMIJUOrbGLYmfY0cw+oZrGWQC7zffknnd7W8uZZr9LGcrM Dbdz02z/F7xbeM5GwCb260Y+ymcNRqp4YjO8sY8pDaxilQNov9L21pMip0Ds7N/azb rc6wo1lMDHWt5XK7g3XE/+sAe+b2YHvCLbUOUGuM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Dec 2024 18:54:40 +0100 Subject: [PATCH 2/5] s390/ipl: 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: <20241211-sysfs-const-bin_attr-s390-v1-2-be01f66bfcf7@weissschuh.net> References: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> In-Reply-To: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Vineeth Vijayan , Peter Oberparleiter , Harald Freudenberger , Holger Dengler Cc: linux-s390@vger.kernel.org, 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=1733939680; l=11532; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=12hHO6niZJCGhDppSxFeOOejXGKMBYthJ3BtK3jvRTk=; b=dOJco9ecFmAWupmBRF/pti0kK3NFAOnxA3nOy+C6NKPdLAHK49ckiSV48geXcHMuSCHQ0rsX8 EHa7PKxT0SACaUZtN2nmFg5np2iTF+JV3BTQJfko6/NHRbHup8nuIi0 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 Acked-by: Alexander Gordeev --- arch/s390/kernel/ipl.c | 142 ++++++++++++++++++++++++---------------------= ---- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c index edbb52ce3f1ec23d8e464fce3fddee64d2327848..5291e6dd347d3cb4d1d8c5812ce= 1d5ad2b5a326d 100644 --- a/arch/s390/kernel/ipl.c +++ b/arch/s390/kernel/ipl.c @@ -280,58 +280,58 @@ static struct kobj_attribute sys_##_prefix##_##_name#= #_attr =3D \ sys_##_prefix##_##_name##_show, \ sys_##_prefix##_##_name##_store) =20 -#define IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \ -static ssize_t sys_##_prefix##_scp_data_show(struct file *filp, \ - struct kobject *kobj, \ - struct bin_attribute *attr, \ - char *buf, loff_t off, \ - size_t count) \ -{ \ - size_t size =3D _ipl_block.scp_data_len; \ - void *scp_data =3D _ipl_block.scp_data; \ - \ - return memory_read_from_buffer(buf, count, &off, \ - scp_data, size); \ +#define IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \ +static ssize_t sys_##_prefix##_scp_data_show(struct file *filp, \ + struct kobject *kobj, \ + const struct bin_attribute *attr, \ + char *buf, loff_t off, \ + size_t count) \ +{ \ + size_t size =3D _ipl_block.scp_data_len; \ + void *scp_data =3D _ipl_block.scp_data; \ + \ + return memory_read_from_buffer(buf, count, &off, \ + scp_data, size); \ } =20 #define IPL_ATTR_SCP_DATA_STORE_FN(_prefix, _ipl_block_hdr, _ipl_block, _i= pl_bp_len, _ipl_bp0_len)\ -static ssize_t sys_##_prefix##_scp_data_store(struct file *filp, \ - struct kobject *kobj, \ - struct bin_attribute *attr, \ - char *buf, loff_t off, \ - size_t count) \ -{ \ - size_t scpdata_len =3D count; \ - size_t padding; \ - \ - if (off) \ - return -EINVAL; \ - \ - memcpy(_ipl_block.scp_data, buf, count); \ - if (scpdata_len % 8) { \ - padding =3D 8 - (scpdata_len % 8); \ - memset(_ipl_block.scp_data + scpdata_len, \ - 0, padding); \ - scpdata_len +=3D padding; \ - } \ - \ - _ipl_block_hdr.len =3D _ipl_bp_len + scpdata_len; \ - _ipl_block.len =3D _ipl_bp0_len + scpdata_len; \ - _ipl_block.scp_data_len =3D scpdata_len; \ - \ - return count; \ +static ssize_t sys_##_prefix##_scp_data_store(struct file *filp, \ + struct kobject *kobj, \ + const struct bin_attribute *attr, \ + char *buf, loff_t off, \ + size_t count) \ +{ \ + size_t scpdata_len =3D count; \ + size_t padding; \ + \ + if (off) \ + return -EINVAL; \ + \ + memcpy(_ipl_block.scp_data, buf, count); \ + if (scpdata_len % 8) { \ + padding =3D 8 - (scpdata_len % 8); \ + memset(_ipl_block.scp_data + scpdata_len, \ + 0, padding); \ + scpdata_len +=3D padding; \ + } \ + \ + _ipl_block_hdr.len =3D _ipl_bp_len + scpdata_len; \ + _ipl_block.len =3D _ipl_bp0_len + scpdata_len; \ + _ipl_block.scp_data_len =3D scpdata_len; \ + \ + return count; \ } =20 #define DEFINE_IPL_ATTR_SCP_DATA_RO(_prefix, _ipl_block, _size) \ IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \ -static struct bin_attribute sys_##_prefix##_scp_data_attr =3D \ +static const struct bin_attribute sys_##_prefix##_scp_data_attr =3D \ __BIN_ATTR(scp_data, 0444, sys_##_prefix##_scp_data_show, \ NULL, _size) =20 #define DEFINE_IPL_ATTR_SCP_DATA_RW(_prefix, _ipl_block_hdr, _ipl_block, _= ipl_bp_len, _ipl_bp0_len, _size)\ IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \ IPL_ATTR_SCP_DATA_STORE_FN(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_le= n, _ipl_bp0_len)\ -static struct bin_attribute sys_##_prefix##_scp_data_attr =3D \ +static const struct bin_attribute sys_##_prefix##_scp_data_attr =3D \ __BIN_ATTR(scp_data, 0644, sys_##_prefix##_scp_data_show, \ sys_##_prefix##_scp_data_store, _size) =20 @@ -434,19 +434,19 @@ static struct kobj_attribute sys_ipl_device_attr =3D __ATTR(device, 0444, sys_ipl_device_show, NULL); =20 static ssize_t sys_ipl_parameter_read(struct file *filp, struct kobject *k= obj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { return memory_read_from_buffer(buf, count, &off, &ipl_block, ipl_block.hdr.len); } -static struct bin_attribute sys_ipl_parameter_attr =3D +static const struct bin_attribute sys_ipl_parameter_attr =3D __BIN_ATTR(binary_parameter, 0444, sys_ipl_parameter_read, NULL, PAGE_SIZE); =20 DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_fcp, ipl_block.fcp, PAGE_SIZE); =20 -static struct bin_attribute *ipl_fcp_bin_attrs[] =3D { +static const struct bin_attribute *const ipl_fcp_bin_attrs[] =3D { &sys_ipl_parameter_attr, &sys_ipl_fcp_scp_data_attr, NULL, @@ -454,7 +454,7 @@ static struct bin_attribute *ipl_fcp_bin_attrs[] =3D { =20 DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_nvme, ipl_block.nvme, PAGE_SIZE); =20 -static struct bin_attribute *ipl_nvme_bin_attrs[] =3D { +static const struct bin_attribute *const ipl_nvme_bin_attrs[] =3D { &sys_ipl_parameter_attr, &sys_ipl_nvme_scp_data_attr, NULL, @@ -462,7 +462,7 @@ static struct bin_attribute *ipl_nvme_bin_attrs[] =3D { =20 DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_eckd, ipl_block.eckd, PAGE_SIZE); =20 -static struct bin_attribute *ipl_eckd_bin_attrs[] =3D { +static const struct bin_attribute *const ipl_eckd_bin_attrs[] =3D { &sys_ipl_parameter_attr, &sys_ipl_eckd_scp_data_attr, NULL, @@ -593,9 +593,9 @@ static struct attribute *ipl_fcp_attrs[] =3D { NULL, }; =20 -static struct attribute_group ipl_fcp_attr_group =3D { +static const struct attribute_group ipl_fcp_attr_group =3D { .attrs =3D ipl_fcp_attrs, - .bin_attrs =3D ipl_fcp_bin_attrs, + .bin_attrs_new =3D ipl_fcp_bin_attrs, }; =20 static struct attribute *ipl_nvme_attrs[] =3D { @@ -607,9 +607,9 @@ static struct attribute *ipl_nvme_attrs[] =3D { NULL, }; =20 -static struct attribute_group ipl_nvme_attr_group =3D { +static const struct attribute_group ipl_nvme_attr_group =3D { .attrs =3D ipl_nvme_attrs, - .bin_attrs =3D ipl_nvme_bin_attrs, + .bin_attrs_new =3D ipl_nvme_bin_attrs, }; =20 static struct attribute *ipl_eckd_attrs[] =3D { @@ -620,9 +620,9 @@ static struct attribute *ipl_eckd_attrs[] =3D { NULL, }; =20 -static struct attribute_group ipl_eckd_attr_group =3D { +static const struct attribute_group ipl_eckd_attr_group =3D { .attrs =3D ipl_eckd_attrs, - .bin_attrs =3D ipl_eckd_bin_attrs, + .bin_attrs_new =3D ipl_eckd_bin_attrs, }; =20 /* CCW ipl device attributes */ @@ -640,11 +640,11 @@ static struct attribute *ipl_ccw_attrs_lpar[] =3D { NULL, }; =20 -static struct attribute_group ipl_ccw_attr_group_vm =3D { +static const struct attribute_group ipl_ccw_attr_group_vm =3D { .attrs =3D ipl_ccw_attrs_vm, }; =20 -static struct attribute_group ipl_ccw_attr_group_lpar =3D { +static const struct attribute_group ipl_ccw_attr_group_lpar =3D { .attrs =3D ipl_ccw_attrs_lpar }; =20 @@ -655,7 +655,7 @@ static struct attribute *ipl_common_attrs[] =3D { NULL, }; =20 -static struct attribute_group ipl_common_attr_group =3D { +static const struct attribute_group ipl_common_attr_group =3D { .attrs =3D ipl_common_attrs, }; =20 @@ -808,7 +808,7 @@ DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_fcp, reipl_block_fcp-= >hdr, IPL_BP_FCP_LEN, IPL_BP0_FCP_LEN, DIAG308_SCPDATA_SIZE); =20 -static struct bin_attribute *reipl_fcp_bin_attrs[] =3D { +static const struct bin_attribute *const reipl_fcp_bin_attrs[] =3D { &sys_reipl_fcp_scp_data_attr, NULL, }; @@ -917,9 +917,9 @@ static struct attribute *reipl_fcp_attrs[] =3D { NULL, }; =20 -static struct attribute_group reipl_fcp_attr_group =3D { +static const struct attribute_group reipl_fcp_attr_group =3D { .attrs =3D reipl_fcp_attrs, - .bin_attrs =3D reipl_fcp_bin_attrs, + .bin_attrs_new =3D reipl_fcp_bin_attrs, }; =20 static struct kobj_attribute sys_reipl_fcp_clear_attr =3D @@ -932,7 +932,7 @@ DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_nvme, reipl_block_nvm= e->hdr, IPL_BP_NVME_LEN, IPL_BP0_NVME_LEN, DIAG308_SCPDATA_SIZE); =20 -static struct bin_attribute *reipl_nvme_bin_attrs[] =3D { +static const struct bin_attribute *const reipl_nvme_bin_attrs[] =3D { &sys_reipl_nvme_scp_data_attr, NULL, }; @@ -955,9 +955,9 @@ static struct attribute *reipl_nvme_attrs[] =3D { NULL, }; =20 -static struct attribute_group reipl_nvme_attr_group =3D { +static const struct attribute_group reipl_nvme_attr_group =3D { .attrs =3D reipl_nvme_attrs, - .bin_attrs =3D reipl_nvme_bin_attrs + .bin_attrs_new =3D reipl_nvme_bin_attrs }; =20 static ssize_t reipl_nvme_clear_show(struct kobject *kobj, @@ -1031,7 +1031,7 @@ DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_eckd, reipl_block_e= ckd->hdr, IPL_BP_ECKD_LEN, IPL_BP0_ECKD_LEN, DIAG308_SCPDATA_SIZE); =20 -static struct bin_attribute *reipl_eckd_bin_attrs[] =3D { +static const struct bin_attribute *const reipl_eckd_bin_attrs[] =3D { &sys_reipl_eckd_scp_data_attr, NULL, }; @@ -1048,9 +1048,9 @@ static struct attribute *reipl_eckd_attrs[] =3D { NULL, }; =20 -static struct attribute_group reipl_eckd_attr_group =3D { +static const struct attribute_group reipl_eckd_attr_group =3D { .attrs =3D reipl_eckd_attrs, - .bin_attrs =3D reipl_eckd_bin_attrs + .bin_attrs_new =3D reipl_eckd_bin_attrs }; =20 static ssize_t reipl_eckd_clear_show(struct kobject *kobj, @@ -1587,15 +1587,15 @@ static struct attribute *dump_fcp_attrs[] =3D { NULL, }; =20 -static struct bin_attribute *dump_fcp_bin_attrs[] =3D { +static const struct bin_attribute *const dump_fcp_bin_attrs[] =3D { &sys_dump_fcp_scp_data_attr, NULL, }; =20 -static struct attribute_group dump_fcp_attr_group =3D { +static const struct attribute_group dump_fcp_attr_group =3D { .name =3D IPL_FCP_STR, .attrs =3D dump_fcp_attrs, - .bin_attrs =3D dump_fcp_bin_attrs, + .bin_attrs_new =3D dump_fcp_bin_attrs, }; =20 /* NVME dump device attributes */ @@ -1621,15 +1621,15 @@ static struct attribute *dump_nvme_attrs[] =3D { NULL, }; =20 -static struct bin_attribute *dump_nvme_bin_attrs[] =3D { +static const struct bin_attribute *const dump_nvme_bin_attrs[] =3D { &sys_dump_nvme_scp_data_attr, NULL, }; =20 -static struct attribute_group dump_nvme_attr_group =3D { +static const struct attribute_group dump_nvme_attr_group =3D { .name =3D IPL_NVME_STR, .attrs =3D dump_nvme_attrs, - .bin_attrs =3D dump_nvme_bin_attrs, + .bin_attrs_new =3D dump_nvme_bin_attrs, }; =20 /* ECKD dump device attributes */ @@ -1655,15 +1655,15 @@ static struct attribute *dump_eckd_attrs[] =3D { NULL, }; =20 -static struct bin_attribute *dump_eckd_bin_attrs[] =3D { +static const struct bin_attribute *const dump_eckd_bin_attrs[] =3D { &sys_dump_eckd_scp_data_attr, NULL, }; =20 -static struct attribute_group dump_eckd_attr_group =3D { +static const struct attribute_group dump_eckd_attr_group =3D { .name =3D IPL_ECKD_STR, .attrs =3D dump_eckd_attrs, - .bin_attrs =3D dump_eckd_bin_attrs, + .bin_attrs_new =3D dump_eckd_bin_attrs, }; =20 /* CCW dump device attributes */ --=20 2.47.1 From nobody Sun Dec 14 13:49:50 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 8CC5D1FF1DF; Wed, 11 Dec 2024 17:54:42 +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=1733939684; cv=none; b=gbrGbEDv5/Al6yYh/Es9z4IjI5OWWmIW2jNuu0SBLyY8WN4YzlKMkda8ynaG1UDj96eIfr5zDxrUKxSrnr/PcatMzqMGQMpv92MqejnQqM5dXU/T5YjeroeRbC2uXdkQshB1rNQ5BbkZvsIQO3OHz+VqcqnA8NrQhjJp17xKyfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733939684; c=relaxed/simple; bh=JVQjkpYq0m8NNLrkS5kkhx1NJZrlRJn/xCgBxc5Xuxw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b2pyeBSdznH14i70f3RTanf8eyi2fvyEcWJaE1FMb75pKiXMdjsNPWo4Ca17O8VvIZZVtoR0hp6NUbaxjcLb1nZv/VHxcKPAhSKMwRhegyzeI8j+25cZVfUvzDjJ2OnkfWqR+3FkNG6kPWWYUH7hkcC6nW/6BqUW3fCmbkYTAyI= 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=HJjTPiDw; 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="HJjTPiDw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733939680; bh=JVQjkpYq0m8NNLrkS5kkhx1NJZrlRJn/xCgBxc5Xuxw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HJjTPiDwphn1YGm/cqVJoW6rmE2EQ3VLZ+FEoyMkhUZVUl1FMJ4llfc5ZNb3ZnhNE 0XVRPX6gP6tfaFYWvSUBKDwoJi2/ufZxVEKnx0ARYxQGr0wwSLzgrDqrjlYJWVNvqw xhPB7orAJMxLaFSajc+Q8KxY8elPLc8gG2ansxgY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Dec 2024 18:54:41 +0100 Subject: [PATCH 3/5] s390/pci: 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: <20241211-sysfs-const-bin_attr-s390-v1-3-be01f66bfcf7@weissschuh.net> References: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> In-Reply-To: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Vineeth Vijayan , Peter Oberparleiter , Harald Freudenberger , Holger Dengler Cc: linux-s390@vger.kernel.org, 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=1733939680; l=2547; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=JVQjkpYq0m8NNLrkS5kkhx1NJZrlRJn/xCgBxc5Xuxw=; b=K0tDhaO073OA7SbwOive+JxY3MHkp1wAoAWMGk7xawBIqh9mSxKVhZmX3UoE+iSsNLO0uyWO/ 8FXWt7yr+M+BbNeXd1Yal19Bz+T7R2MHMgHLWe7+nmYSTq1JwMp4y3F 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 Acked-by: Alexander Gordeev --- arch/s390/pci/pci_sysfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/s390/pci/pci_sysfs.c b/arch/s390/pci/pci_sysfs.c index 5f46ad58dcd1c3fda7e95aeabcdd10cdf9efd64e..2de1ea6c3a8cbd7cccc9c100569= 6eb96fd4d75dd 100644 --- a/arch/s390/pci/pci_sysfs.c +++ b/arch/s390/pci/pci_sysfs.c @@ -135,7 +135,7 @@ static ssize_t recover_store(struct device *dev, struct= device_attribute *attr, static DEVICE_ATTR_WO(recover); =20 static ssize_t util_string_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct device *dev =3D kobj_to_dev(kobj); @@ -145,10 +145,10 @@ static ssize_t util_string_read(struct file *filp, st= ruct kobject *kobj, return memory_read_from_buffer(buf, count, &off, zdev->util_str, sizeof(zdev->util_str)); } -static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN); +static const BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN); =20 static ssize_t report_error_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct zpci_report_error_header *report =3D (void *) buf; @@ -164,7 +164,7 @@ static ssize_t report_error_write(struct file *filp, st= ruct kobject *kobj, =20 return ret ? ret : count; } -static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE= ); +static const BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAG= E_SIZE); =20 static ssize_t uid_is_unique_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -203,7 +203,7 @@ const struct attribute_group zpci_ident_attr_group =3D { .is_visible =3D zpci_index_is_visible, }; =20 -static struct bin_attribute *zpci_bin_attrs[] =3D { +static const struct bin_attribute *const zpci_bin_attrs[] =3D { &bin_attr_util_string, &bin_attr_report_error, NULL, @@ -227,7 +227,7 @@ static struct attribute *zpci_dev_attrs[] =3D { =20 const struct attribute_group zpci_attr_group =3D { .attrs =3D zpci_dev_attrs, - .bin_attrs =3D zpci_bin_attrs, + .bin_attrs_new =3D zpci_bin_attrs, }; =20 static struct attribute *pfip_attrs[] =3D { --=20 2.47.1 From nobody Sun Dec 14 13:49:50 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 6B7031FF1D1; Wed, 11 Dec 2024 17:54:42 +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=1733939684; cv=none; b=JLaacBWDUi9AKfeD0natVdv4cYN58sMXptxcTWqiOqzd/27mOfvY6UxmuS9g+UNIQiopkqprdMHXLoNFhJUabyHz1E7RCW/oaY2T48vAA9bF62Xb55S1eEK3vz01TE3VFsXijl1wVEaQVwzMF5hhLN+2kOM2jAwyn4e8AQ4gjSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733939684; c=relaxed/simple; bh=WJ1JLrL8V13d4lDWJbvW3CzFfSfBUFy9QVkkKqUwJCo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qv4iBz+8LTHwNJHg0PxFUEKOdqZrcZgC6FoURYHpwqVF67MAcvvk4YDwuFiDp1cqXAlF+Yory7ZwB2bTdy4Y4h24ifsKCTIyO2b6ZNVfDLeZu6WogXpX6YJrq+EiWaUSyvKKaz8JH/2E+5dnPzJLvvPhghAka8KlHOu9igEIPrg= 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=O+6t9X7U; 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="O+6t9X7U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733939680; bh=WJ1JLrL8V13d4lDWJbvW3CzFfSfBUFy9QVkkKqUwJCo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=O+6t9X7U7J2nqTcvRCtnKuiMx4rmlecVubIX/cWHQDEPR54I87dK1mD2vGEmfl+fD Z2Daju995EEtCC5ck/pbaCQPN9iurpFs6HvGFjLQVb0/d6UE7dn4Vh87kmDkhcbGBk MkHeoedAtlWwk0spDYBmZqLsKRvCUkxHow/5LMXc= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Dec 2024 18:54:42 +0100 Subject: [PATCH 4/5] s390/sclp: 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: <20241211-sysfs-const-bin_attr-s390-v1-4-be01f66bfcf7@weissschuh.net> References: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> In-Reply-To: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Vineeth Vijayan , Peter Oberparleiter , Harald Freudenberger , Holger Dengler Cc: linux-s390@vger.kernel.org, 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=1733939680; l=2161; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=WJ1JLrL8V13d4lDWJbvW3CzFfSfBUFy9QVkkKqUwJCo=; b=X9fGukjy/L3Ky3Y10NF3t1Nm9TXaG9O/i7fYKaIj1hDOptRIGsYRueBHyRLFOcWjc4wAQDOQP RkFJ9pWvsojDXeKHVPRZoGRCbNqbVSA1V0tspD0tIYKaAqlcyQsf+u3 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 Acked-by: Alexander Gordeev --- drivers/s390/char/sclp_config.c | 4 ++-- drivers/s390/char/sclp_sd.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/s390/char/sclp_config.c b/drivers/s390/char/sclp_confi= g.c index f56ea9b60e08e817652a9b7d19d420e9977c6552..ae5d289871779cc5cc1f3070c64= 746ea702eb41d 100644 --- a/drivers/s390/char/sclp_config.c +++ b/drivers/s390/char/sclp_config.c @@ -128,7 +128,7 @@ static int sclp_ofb_send_req(char *ev_data, size_t len) } =20 static ssize_t sysfs_ofb_data_write(struct file *filp, struct kobject *kob= j, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { int rc; @@ -142,7 +142,7 @@ static const struct bin_attribute ofb_bin_attr =3D { .name =3D "event_data", .mode =3D S_IWUSR, }, - .write =3D sysfs_ofb_data_write, + .write_new =3D sysfs_ofb_data_write, }; #endif =20 diff --git a/drivers/s390/char/sclp_sd.c b/drivers/s390/char/sclp_sd.c index c2dc9aadb7d2c213c93c4fb5e4cdf66d18fc1f78..8524c14affed68587cace9c2e8a= c1f02f87052de 100644 --- a/drivers/s390/char/sclp_sd.c +++ b/drivers/s390/char/sclp_sd.c @@ -476,7 +476,7 @@ static struct kobj_type sclp_sd_file_ktype =3D { * on EOF. */ static ssize_t data_read(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, char *buffer, + const struct bin_attribute *attr, char *buffer, loff_t off, size_t size) { struct sclp_sd_file *sd_file =3D to_sd_file(kobj); @@ -539,7 +539,7 @@ static __init struct sclp_sd_file *sclp_sd_file_create(= const char *name, u8 di) sysfs_bin_attr_init(&sd_file->data_attr); sd_file->data_attr.attr.name =3D "data"; sd_file->data_attr.attr.mode =3D 0444; - sd_file->data_attr.read =3D data_read; + sd_file->data_attr.read_new =3D data_read; =20 rc =3D sysfs_create_bin_file(&sd_file->kobj, &sd_file->data_attr); if (rc) { --=20 2.47.1 From nobody Sun Dec 14 13:49:50 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 93AD0202F9E; Wed, 11 Dec 2024 17:54:45 +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=1733939687; cv=none; b=rvtWOSPm6ylx27R0zg2dkAPhl+2RS1eaMIZbDjf6gVmoFtC4taMV3DxH8vDE8hW2rmqOIOb7Vg5VlB76DNWqAm9/0wuN3xJoX5NopvInoKoliU+75jRnbs8sXXDUqhVsFleOeq+RGOKkRwXeIDU+BP/mlz/5EDoUx24IYpszUkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733939687; c=relaxed/simple; bh=khp6Kp6PQ4N5d8E6nOwINYUtZHWHtP2p0DSv3OfHocI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o9IRMWMZ/76jBXUF5cz7ucRIMZPhQ+9XCeeEcnKJl/gAVE6ZI2q/6Ht8BxAX5GStw7MklkC82wUy1IS8MEaD2w2sDpC8cLR2BzGuN5iFZhvTeajUg0ME5IHHCIMU391NwHeJQImgCDJUVoB3iIyoW3Fu/B1CXGp4bXX6YcP/2/Y= 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=tTWqH3Uf; 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="tTWqH3Uf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733939680; bh=khp6Kp6PQ4N5d8E6nOwINYUtZHWHtP2p0DSv3OfHocI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tTWqH3UfjkXEV8dbGPLkR9aYXWMHF/H3t5hK0V4GiCaHpAYNtkMNt1rlZG6HXOK+0 OZ2dde3392CtRtxAbXb5gH/u4fch+HcowSb7EeIS1vpAp0fRGI4IpS/J8VA3ovmei/ IoK1qxxKr/rPH8NDXbNL5OUikDbDmvYmL7JaixJI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Dec 2024 18:54:43 +0100 Subject: [PATCH 5/5] s390/pkey: 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: <20241211-sysfs-const-bin_attr-s390-v1-5-be01f66bfcf7@weissschuh.net> References: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> In-Reply-To: <20241211-sysfs-const-bin_attr-s390-v1-0-be01f66bfcf7@weissschuh.net> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Vineeth Vijayan , Peter Oberparleiter , Harald Freudenberger , Holger Dengler Cc: linux-s390@vger.kernel.org, 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=1733939680; l=14342; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=khp6Kp6PQ4N5d8E6nOwINYUtZHWHtP2p0DSv3OfHocI=; b=RlgLX++1AVH08W/1E8c2XzAnU0VZ837lB69QhXVzfiXnq+wd4v6nMXA5xe/kyJNT8rth7P/UT iwrjv2/0oU5Dw0eGxytahrGhjggyNfQXffCKW/wXIC/ImaBIaqJboVr 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 Reviewed-by: Holger Dengler Tested-by: Holger Dengler --- drivers/s390/crypto/pkey_sysfs.c | 128 +++++++++++++++++++----------------= ---- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/drivers/s390/crypto/pkey_sysfs.c b/drivers/s390/crypto/pkey_sy= sfs.c index a4eb45803f5e6d6b17dec709e6068448973399f6..57edc97bafd29483eedc405d47e= abe3d7f6c28fc 100644 --- a/drivers/s390/crypto/pkey_sysfs.c +++ b/drivers/s390/crypto/pkey_sysfs.c @@ -184,7 +184,7 @@ static ssize_t pkey_protkey_hmac_attr_read(u32 keytype,= char *buf, =20 static ssize_t protkey_aes_128_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -194,7 +194,7 @@ static ssize_t protkey_aes_128_read(struct file *filp, =20 static ssize_t protkey_aes_192_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -204,7 +204,7 @@ static ssize_t protkey_aes_192_read(struct file *filp, =20 static ssize_t protkey_aes_256_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -214,7 +214,7 @@ static ssize_t protkey_aes_256_read(struct file *filp, =20 static ssize_t protkey_aes_128_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -224,7 +224,7 @@ static ssize_t protkey_aes_128_xts_read(struct file *fi= lp, =20 static ssize_t protkey_aes_256_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -234,7 +234,7 @@ static ssize_t protkey_aes_256_xts_read(struct file *fi= lp, =20 static ssize_t protkey_aes_xts_128_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -244,7 +244,7 @@ static ssize_t protkey_aes_xts_128_read(struct file *fi= lp, =20 static ssize_t protkey_aes_xts_256_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -254,7 +254,7 @@ static ssize_t protkey_aes_xts_256_read(struct file *fi= lp, =20 static ssize_t protkey_hmac_512_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -264,7 +264,7 @@ static ssize_t protkey_hmac_512_read(struct file *filp, =20 static ssize_t protkey_hmac_1024_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -272,17 +272,17 @@ static ssize_t protkey_hmac_1024_read(struct file *fi= lp, buf, off, count); } =20 -static BIN_ATTR_RO(protkey_aes_128, sizeof(struct protaeskeytoken)); -static BIN_ATTR_RO(protkey_aes_192, sizeof(struct protaeskeytoken)); -static BIN_ATTR_RO(protkey_aes_256, sizeof(struct protaeskeytoken)); -static BIN_ATTR_RO(protkey_aes_128_xts, 2 * sizeof(struct protaeskeytoken)= ); -static BIN_ATTR_RO(protkey_aes_256_xts, 2 * sizeof(struct protaeskeytoken)= ); -static BIN_ATTR_RO(protkey_aes_xts_128, sizeof(struct protkeytoken) + 64); -static BIN_ATTR_RO(protkey_aes_xts_256, sizeof(struct protkeytoken) + 96); -static BIN_ATTR_RO(protkey_hmac_512, sizeof(struct protkeytoken) + 96); -static BIN_ATTR_RO(protkey_hmac_1024, sizeof(struct protkeytoken) + 160); - -static struct bin_attribute *protkey_attrs[] =3D { +static const BIN_ATTR_RO(protkey_aes_128, sizeof(struct protaeskeytoken)); +static const BIN_ATTR_RO(protkey_aes_192, sizeof(struct protaeskeytoken)); +static const BIN_ATTR_RO(protkey_aes_256, sizeof(struct protaeskeytoken)); +static const BIN_ATTR_RO(protkey_aes_128_xts, 2 * sizeof(struct protaeskey= token)); +static const BIN_ATTR_RO(protkey_aes_256_xts, 2 * sizeof(struct protaeskey= token)); +static const BIN_ATTR_RO(protkey_aes_xts_128, sizeof(struct protkeytoken) = + 64); +static const BIN_ATTR_RO(protkey_aes_xts_256, sizeof(struct protkeytoken) = + 96); +static const BIN_ATTR_RO(protkey_hmac_512, sizeof(struct protkeytoken) + 9= 6); +static const BIN_ATTR_RO(protkey_hmac_1024, sizeof(struct protkeytoken) + = 160); + +static const struct bin_attribute *const protkey_attrs[] =3D { &bin_attr_protkey_aes_128, &bin_attr_protkey_aes_192, &bin_attr_protkey_aes_256, @@ -295,9 +295,9 @@ static struct bin_attribute *protkey_attrs[] =3D { NULL }; =20 -static struct attribute_group protkey_attr_group =3D { - .name =3D "protkey", - .bin_attrs =3D protkey_attrs, +static const struct attribute_group protkey_attr_group =3D { + .name =3D "protkey", + .bin_attrs_new =3D protkey_attrs, }; =20 /* @@ -341,7 +341,7 @@ static ssize_t pkey_ccadata_aes_attr_read(u32 keytype, = bool is_xts, char *buf, =20 static ssize_t ccadata_aes_128_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -351,7 +351,7 @@ static ssize_t ccadata_aes_128_read(struct file *filp, =20 static ssize_t ccadata_aes_192_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -361,7 +361,7 @@ static ssize_t ccadata_aes_192_read(struct file *filp, =20 static ssize_t ccadata_aes_256_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -371,7 +371,7 @@ static ssize_t ccadata_aes_256_read(struct file *filp, =20 static ssize_t ccadata_aes_128_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -381,7 +381,7 @@ static ssize_t ccadata_aes_128_xts_read(struct file *fi= lp, =20 static ssize_t ccadata_aes_256_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -389,13 +389,13 @@ static ssize_t ccadata_aes_256_xts_read(struct file *= filp, off, count); } =20 -static BIN_ATTR_RO(ccadata_aes_128, sizeof(struct secaeskeytoken)); -static BIN_ATTR_RO(ccadata_aes_192, sizeof(struct secaeskeytoken)); -static BIN_ATTR_RO(ccadata_aes_256, sizeof(struct secaeskeytoken)); -static BIN_ATTR_RO(ccadata_aes_128_xts, 2 * sizeof(struct secaeskeytoken)); -static BIN_ATTR_RO(ccadata_aes_256_xts, 2 * sizeof(struct secaeskeytoken)); +static const BIN_ATTR_RO(ccadata_aes_128, sizeof(struct secaeskeytoken)); +static const BIN_ATTR_RO(ccadata_aes_192, sizeof(struct secaeskeytoken)); +static const BIN_ATTR_RO(ccadata_aes_256, sizeof(struct secaeskeytoken)); +static const BIN_ATTR_RO(ccadata_aes_128_xts, 2 * sizeof(struct secaeskeyt= oken)); +static const BIN_ATTR_RO(ccadata_aes_256_xts, 2 * sizeof(struct secaeskeyt= oken)); =20 -static struct bin_attribute *ccadata_attrs[] =3D { +static const struct bin_attribute *const ccadata_attrs[] =3D { &bin_attr_ccadata_aes_128, &bin_attr_ccadata_aes_192, &bin_attr_ccadata_aes_256, @@ -404,9 +404,9 @@ static struct bin_attribute *ccadata_attrs[] =3D { NULL }; =20 -static struct attribute_group ccadata_attr_group =3D { - .name =3D "ccadata", - .bin_attrs =3D ccadata_attrs, +static const struct attribute_group ccadata_attr_group =3D { + .name =3D "ccadata", + .bin_attrs_new =3D ccadata_attrs, }; =20 #define CCACIPHERTOKENSIZE (sizeof(struct cipherkeytoken) + 80) @@ -455,7 +455,7 @@ static ssize_t pkey_ccacipher_aes_attr_read(enum pkey_k= ey_size keybits, =20 static ssize_t ccacipher_aes_128_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -465,7 +465,7 @@ static ssize_t ccacipher_aes_128_read(struct file *filp, =20 static ssize_t ccacipher_aes_192_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -475,7 +475,7 @@ static ssize_t ccacipher_aes_192_read(struct file *filp, =20 static ssize_t ccacipher_aes_256_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -485,7 +485,7 @@ static ssize_t ccacipher_aes_256_read(struct file *filp, =20 static ssize_t ccacipher_aes_128_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -495,7 +495,7 @@ static ssize_t ccacipher_aes_128_xts_read(struct file *= filp, =20 static ssize_t ccacipher_aes_256_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -503,13 +503,13 @@ static ssize_t ccacipher_aes_256_xts_read(struct file= *filp, off, count); } =20 -static BIN_ATTR_RO(ccacipher_aes_128, CCACIPHERTOKENSIZE); -static BIN_ATTR_RO(ccacipher_aes_192, CCACIPHERTOKENSIZE); -static BIN_ATTR_RO(ccacipher_aes_256, CCACIPHERTOKENSIZE); -static BIN_ATTR_RO(ccacipher_aes_128_xts, 2 * CCACIPHERTOKENSIZE); -static BIN_ATTR_RO(ccacipher_aes_256_xts, 2 * CCACIPHERTOKENSIZE); +static const BIN_ATTR_RO(ccacipher_aes_128, CCACIPHERTOKENSIZE); +static const BIN_ATTR_RO(ccacipher_aes_192, CCACIPHERTOKENSIZE); +static const BIN_ATTR_RO(ccacipher_aes_256, CCACIPHERTOKENSIZE); +static const BIN_ATTR_RO(ccacipher_aes_128_xts, 2 * CCACIPHERTOKENSIZE); +static const BIN_ATTR_RO(ccacipher_aes_256_xts, 2 * CCACIPHERTOKENSIZE); =20 -static struct bin_attribute *ccacipher_attrs[] =3D { +static const struct bin_attribute *const ccacipher_attrs[] =3D { &bin_attr_ccacipher_aes_128, &bin_attr_ccacipher_aes_192, &bin_attr_ccacipher_aes_256, @@ -518,9 +518,9 @@ static struct bin_attribute *ccacipher_attrs[] =3D { NULL }; =20 -static struct attribute_group ccacipher_attr_group =3D { - .name =3D "ccacipher", - .bin_attrs =3D ccacipher_attrs, +static const struct attribute_group ccacipher_attr_group =3D { + .name =3D "ccacipher", + .bin_attrs_new =3D ccacipher_attrs, }; =20 /* @@ -570,7 +570,7 @@ static ssize_t pkey_ep11_aes_attr_read(enum pkey_key_si= ze keybits, =20 static ssize_t ep11_aes_128_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -580,7 +580,7 @@ static ssize_t ep11_aes_128_read(struct file *filp, =20 static ssize_t ep11_aes_192_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -590,7 +590,7 @@ static ssize_t ep11_aes_192_read(struct file *filp, =20 static ssize_t ep11_aes_256_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -600,7 +600,7 @@ static ssize_t ep11_aes_256_read(struct file *filp, =20 static ssize_t ep11_aes_128_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -610,7 +610,7 @@ static ssize_t ep11_aes_128_xts_read(struct file *filp, =20 static ssize_t ep11_aes_256_xts_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { @@ -618,13 +618,13 @@ static ssize_t ep11_aes_256_xts_read(struct file *fil= p, off, count); } =20 -static BIN_ATTR_RO(ep11_aes_128, MAXEP11AESKEYBLOBSIZE); -static BIN_ATTR_RO(ep11_aes_192, MAXEP11AESKEYBLOBSIZE); -static BIN_ATTR_RO(ep11_aes_256, MAXEP11AESKEYBLOBSIZE); -static BIN_ATTR_RO(ep11_aes_128_xts, 2 * MAXEP11AESKEYBLOBSIZE); -static BIN_ATTR_RO(ep11_aes_256_xts, 2 * MAXEP11AESKEYBLOBSIZE); +static const BIN_ATTR_RO(ep11_aes_128, MAXEP11AESKEYBLOBSIZE); +static const BIN_ATTR_RO(ep11_aes_192, MAXEP11AESKEYBLOBSIZE); +static const BIN_ATTR_RO(ep11_aes_256, MAXEP11AESKEYBLOBSIZE); +static const BIN_ATTR_RO(ep11_aes_128_xts, 2 * MAXEP11AESKEYBLOBSIZE); +static const BIN_ATTR_RO(ep11_aes_256_xts, 2 * MAXEP11AESKEYBLOBSIZE); =20 -static struct bin_attribute *ep11_attrs[] =3D { +static const struct bin_attribute *const ep11_attrs[] =3D { &bin_attr_ep11_aes_128, &bin_attr_ep11_aes_192, &bin_attr_ep11_aes_256, @@ -633,9 +633,9 @@ static struct bin_attribute *ep11_attrs[] =3D { NULL }; =20 -static struct attribute_group ep11_attr_group =3D { +static const struct attribute_group ep11_attr_group =3D { .name =3D "ep11", - .bin_attrs =3D ep11_attrs, + .bin_attrs_new =3D ep11_attrs, }; =20 const struct attribute_group *pkey_attr_groups[] =3D { --=20 2.47.1