From patchwork Tue Jan 14 21:32:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13939533 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 73F921ADC82; Tue, 14 Jan 2025 21:32:29 +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=1736890351; cv=none; b=AELoImY3NaAQLlk7Llo0CVqQCreo4Th0Ri+w+k5R9MhVAUO3JcVdtcFJIvJ4WmkL6CaNpntsITHbprMqeeLdxTlloUhtmHHh+3qGEin4yP5nRbya6tA3Y5rreQFufQTSzkpyys9SdGoO1Qrl7EDpk6VZX+enJsGDCW+otStMc5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736890351; c=relaxed/simple; bh=wpLWbQdu715XoabfkX+51VHxRtDq2ljWcOHLnLaZlk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l1VvNK7YM3h0q+vlbOatrHSesaoX8QqT/g4PeKaM2lNPSLraCIpCqOBHrLEqqGSvMnjhozV4srUOQ5CcPVhQsoZOg+rX1/JJcTkVEMQCN65kVOrM9D4y0ETASPzELpDYxf6GnzlSE2uOVItGblIuQX3dm/Mhin5pTDMxBiu6J3c= 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=df9U6CIY; 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="df9U6CIY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1736890347; bh=wpLWbQdu715XoabfkX+51VHxRtDq2ljWcOHLnLaZlk8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=df9U6CIY2xFgFUBZ0wIkojB43lHA1JScVlGJ2UCDtOkJ1Zzdwoab62BxEclZuaWzr eVDWZ4XP06WozxzWM0cCr/WlTUcVw8qS4QW43MTkVetVjIZ4uHRNl1XwnfyTrR7Q8f Q/D2RYLmXm0W5Yml9luc0eXxBbGvitTQE/YlKV8E= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 14 Jan 2025 22:32:13 +0100 Subject: [PATCH 1/2] RDMA/hfi1: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250114-sysfs-const-bin_attr-infiniband-v1-1-397aaa94d453@weissschuh.net> References: <20250114-sysfs-const-bin_attr-infiniband-v1-0-397aaa94d453@weissschuh.net> In-Reply-To: <20250114-sysfs-const-bin_attr-infiniband-v1-0-397aaa94d453@weissschuh.net> To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736890346; l=2544; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=wpLWbQdu715XoabfkX+51VHxRtDq2ljWcOHLnLaZlk8=; b=tyXOvG9ANNpuFxCv+JQdpsunnRt0sjTI9c8tYEEq9VLYiJtsrant14P6Y421jsy5lS2e6vHv0 WJC97M9boctDs/MPsrwkfOHU4qw3g3aRSD+w+3fk1Cwh0SdPvZqqKBi 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ßschuh --- drivers/infiniband/hw/hfi1/sysfs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/sysfs.c b/drivers/infiniband/hw/hfi1/sysfs.c index d62ba5fdd80c876eedf572bde408131202548e9d..d94216c7d576f6418140e0d096314633aa42ab3b 100644 --- a/drivers/infiniband/hw/hfi1/sysfs.c +++ b/drivers/infiniband/hw/hfi1/sysfs.c @@ -27,8 +27,8 @@ static struct hfi1_pportdata *hfi1_get_pportdata_kobj(struct kobject *kobj) * Congestion control table size followed by table entries */ static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, - loff_t pos, size_t count) + const struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) { int ret; struct hfi1_pportdata *ppd = hfi1_get_pportdata_kobj(kobj); @@ -57,7 +57,7 @@ static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj, return count; } -static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE); +static const BIN_ATTR_RO(cc_table_bin, PAGE_SIZE); /* * Congestion settings: port control, control map and an array of 16 @@ -65,7 +65,7 @@ static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE); * trigger threshold and the minimum injection rate delay. */ static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct hfi1_pportdata *ppd = hfi1_get_pportdata_kobj(kobj); @@ -93,9 +93,9 @@ static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj, return count; } -static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE); +static const BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE); -static struct bin_attribute *port_cc_bin_attributes[] = { +static const struct bin_attribute *const port_cc_bin_attributes[] = { &bin_attr_cc_setting_bin, &bin_attr_cc_table_bin, NULL @@ -134,7 +134,7 @@ static struct attribute *port_cc_attributes[] = { static const struct attribute_group port_cc_group = { .name = "CCMgtA", .attrs = port_cc_attributes, - .bin_attrs = port_cc_bin_attributes, + .bin_attrs_new = port_cc_bin_attributes, }; /* Start sc2vl */ From patchwork Tue Jan 14 21:32:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13939534 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 EF3DB1D516A; Tue, 14 Jan 2025 21:32:29 +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=1736890353; cv=none; b=HV17Pd6rwq9kj6keiEbXhe95BfVb1rY3C+B+PKyN2ClnankXwji9+09g6HJjlEt5JmcpfsElbAtFzz3jcT4IlU7EJdNsggBDwBhnNlrJO0ckihpqAGKTnnLtEFWJpC6LyAl1PywJC/mo2WMM6qwjySZ8+vkDsPvOam9MLi0cImU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736890353; c=relaxed/simple; bh=Ubtln1nuhXVXdzBoCLl0VVvDm7xPL2/e9NupIy2VLa4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iV/bdBb5KAButBuTuGNULP32SkQxj6/L6pQUYY3jSnGLNTnNZc3ZNLM1ahEeZHhCtXY/iPNTgtFJrgfGgJkHQ7P3frT9KQQnT4HhyNGMZbJl3tUh7D+acW2bMjhZWCLPQV8DJyThKR8Gf87pwBabc1UXol3nX7NVEhuV4vg0rBA= 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=K3M0+wYB; 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="K3M0+wYB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1736890347; bh=Ubtln1nuhXVXdzBoCLl0VVvDm7xPL2/e9NupIy2VLa4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=K3M0+wYBxdFry5Kj1pyJl7dodunQhyui3WDKInN9IAoVRvGm+hP8KCYwsUrP7rHKc 9LkgOtPwWZp7OZSAfmEkTih141b1z2Ddp/EZQs4XpHWbsbhK7Nzkq8uEykQpftwSK8 gvJZgpzX3mdmnUNFigasUfrieRrRMAJDd84lrVAQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 14 Jan 2025 22:32:14 +0100 Subject: [PATCH 2/2] RDMA/qib: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250114-sysfs-const-bin_attr-infiniband-v1-2-397aaa94d453@weissschuh.net> References: <20250114-sysfs-const-bin_attr-infiniband-v1-0-397aaa94d453@weissschuh.net> In-Reply-To: <20250114-sysfs-const-bin_attr-infiniband-v1-0-397aaa94d453@weissschuh.net> To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736890346; l=2654; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Ubtln1nuhXVXdzBoCLl0VVvDm7xPL2/e9NupIy2VLa4=; b=SXyIae0D/aChk15EqhHVLEWRzdpnfit1rBREp53teSiyLxRbY3hAQbFbNiyjeAjj3DB3snH+s e1muhZYRHk2Ctl6hMM4tL85CDxf/cD6zxTinLd9fDrhbCK45wexlRyY 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ßschuh --- drivers/infiniband/hw/qib/qib_sysfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c index ba2cd68b53e6c240f1afc65c64012c75ccf488e0..805e37dc7621179c94320759f8259144950c2e68 100644 --- a/drivers/infiniband/hw/qib/qib_sysfs.c +++ b/drivers/infiniband/hw/qib/qib_sysfs.c @@ -214,8 +214,8 @@ static const struct attribute_group port_linkcontrol_group = { * Congestion control table size followed by table entries */ static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, - loff_t pos, size_t count) + const struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) { struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj); int ret; @@ -241,7 +241,7 @@ static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj, return count; } -static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE); +static const BIN_ATTR_RO(cc_table_bin, PAGE_SIZE); /* * Congestion settings: port control, control map and an array of 16 @@ -249,8 +249,8 @@ static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE); * trigger threshold and the minimum injection rate delay. */ static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, - loff_t pos, size_t count) + const struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) { struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj); int ret; @@ -274,9 +274,9 @@ static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj, return count; } -static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE); +static const BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE); -static struct bin_attribute *port_ccmgta_attributes[] = { +static const struct bin_attribute *const port_ccmgta_attributes[] = { &bin_attr_cc_setting_bin, &bin_attr_cc_table_bin, NULL, @@ -295,7 +295,7 @@ static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj, static const struct attribute_group port_ccmgta_attribute_group = { .name = "CCMgtA", .is_bin_visible = qib_ccmgta_is_bin_visible, - .bin_attrs = port_ccmgta_attributes, + .bin_attrs_new = port_ccmgta_attributes, }; /* Start sl2vl */