Skip to contentSkip to conversation

Allow to enable CONFIG_FORTIFY_SOURCE

PATCH New Jan Kiszka 1 participant 6 messages Sep 5, 2025

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/5 drivers/analogy/8255: Drop redundant zeroing of subdevice struct

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This is already done by a4l_alloc_subd, both for a4l_subdevice and the succeeding private data. Dropping the memset here also helps resolving CONFIG_FORTIFY_SOURCE findings as subd->priv appears as zero-length to the compiler.

---
 kernel/drivers/analogy/intel/8255.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/drivers/analogy/intel/8255.c +0 -3
index 049c5d2a47..be43dbb6ab 100644
@@ -266,9 +266,6 @@ static int dev_8255_attach(struct a4l_device *dev, a4l_lnkdesc_t *arg)
 			goto out_attach;
 		}
 
-		memset(subd, 0, sizeof(struct a4l_subdevice));
-		memset(subd->priv, 0, sizeof(subd_8255_t));
-
 		subd_8255 = (subd_8255_t *)subd->priv;
 
 		if(request_region(addrs[i], _8255_SIZE, "Analogy 8255") == 0) {
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/5 drivers/analogy/testing: Kill the loop zombie

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

The analogy loop driver was originally deleted via 4f0946ee8abc. Later on, 09f8992a55be brought it back in a source tree restructuring, though without making it buildable again. Since then, it was even "maintained" on code refactorings. Before more cycles are spent on this zombie, eliminate it for real.

---
 kernel/drivers/analogy/testing/Makefile |   2 -
 kernel/drivers/analogy/testing/loop.c   | 285 ------------------------
 2 files changed, 287 deletions(-)
 delete mode 100644 kernel/drivers/analogy/testing/loop.c
kernel/drivers/analogy/testing/Makefile +0 -2
index e92e5bc906..5e4c17f262 100644
@@ -4,5 +4,3 @@ ccflags-y += -I$(srctree)/drivers/xenomai/analogy
 obj-$(CONFIG_XENO_DRIVERS_ANALOGY_FAKE) += analogy_fake.o
 
 analogy_fake-y := fake.o
-
-analogy_loop-y := loop.o
kernel/drivers/analogy/testing/loop.c deleted +0 -285

285 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#5 lore raw

PATCH 5/5 drivers/net/rtcfg: Resolve FORTIFY_SOURCE warnings

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

The rtcfg frame structures are of variable size, depending on the chosen address type. Avoid memcpy to avoid trigging warnings while writing to zero-length fields - which are actually backed by sufficiently sized rtskbs.

---
 kernel/drivers/net/stack/rtcfg/rtcfg_frame.c | 21 ++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
kernel/drivers/net/stack/rtcfg/rtcfg_frame.c +15 -6
index 0c8eb7a878..ca6c130b5f 100644
@@ -167,15 +167,19 @@ int rtcfg_send_stage_1(struct rtcfg_connection *conn)
 
 #if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_RTIPV4)
 	if (stage_1_frm->addr_type == RTCFG_ADDR_IP) {
+		__u32 *ip_addr;
+
 		rtskb_put(rtskb, 2 * RTCFG_ADDRSIZE_IP);
 
-		memcpy(stage_1_frm->client_addr, &(conn->addr.ip_addr), 4);
+		ip_addr = (__u32 *)stage_1_frm->client_addr;
+		*ip_addr = conn->addr.ip_addr;
 
 		stage_1_frm =
 			(struct rtcfg_frm_stage_1_cfg *)(((u8 *)stage_1_frm) +
 							 RTCFG_ADDRSIZE_IP);
 
-		memcpy(stage_1_frm->server_addr, &(rtdev->local_ip), 4);
+		ip_addr = (__u32 *)stage_1_frm->server_addr;
+		*ip_addr = rtdev->local_ip;
 
 		stage_1_frm =
 			(struct rtcfg_frm_stage_1_cfg *)(((u8 *)stage_1_frm) +
@@ -326,9 +330,11 @@ int rtcfg_send_announce_new(int ifindex)
 
 #if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_RTIPV4)
 	if (announce_new->addr_type == RTCFG_ADDR_IP) {
+		__u32 *ip_addr = (__u32 *)announce_new->addr;
+
 		rtskb_put(rtskb, RTCFG_ADDRSIZE_IP);
 
-		memcpy(announce_new->addr, &(rtdev->local_ip), 4);
+		*ip_addr = rtdev->local_ip;
 
 		announce_new =
 			(struct rtcfg_frm_announce *)(((u8 *)announce_new) +
@@ -381,9 +387,11 @@ int rtcfg_send_announce_reply(int ifindex, u8 *dest_mac_addr)
 
 #if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_RTIPV4)
 	if (announce_rpl->addr_type == RTCFG_ADDR_IP) {
+		__u32 *ip_addr = (__u32 *)announce_rpl->addr;
+
 		rtskb_put(rtskb, RTCFG_ADDRSIZE_IP);
 
-		memcpy(announce_rpl->addr, &(rtdev->local_ip), 4);
+		*ip_addr = rtdev->local_ip;
 
 		announce_rpl =
 			(struct rtcfg_frm_announce *)(((u8 *)announce_rpl) +
@@ -498,10 +506,11 @@ int rtcfg_send_dead_station(struct rtcfg_connection *conn)
 
 #if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_RTIPV4)
 	if (dead_station_frm->addr_type == RTCFG_ADDR_IP) {
+		__u32 *ip_addr = (__u32 *)dead_station_frm->logical_addr;
+
 		rtskb_put(rtskb, RTCFG_ADDRSIZE_IP);
 
-		memcpy(dead_station_frm->logical_addr, &(conn->addr.ip_addr),
-		       4);
+		*ip_addr = conn->addr.ip_addr;
 
 		dead_station_frm = (struct rtcfg_frm_dead_station
 					    *)(((u8 *)dead_station_frm) +
Signature · 1 line
2.43.0

Jan Kiszka

author
#0 lore raw

cover Allow to enable CONFIG_FORTIFY_SOURCE

All findings were harmless, so silence them - except for one that was actually pointing to unneeded code.

Along that, a zombie was found and is now eliminated.

Jan

Jan Kiszka (5):
drivers/analogy/8255: Drop redundant zeroing of subdevice struct drivers/analogy/testing: Kill the loop zombie drivers/analogy/testing: Resolve FORTIFY_SOURCE warning drivers/net/eepro100: Silence FORTIFY_SOURCE warning drivers/net/rtcfg: Resolve FORTIFY_SOURCE warnings

 kernel/drivers/analogy/intel/8255.c          |   3 -
 kernel/drivers/analogy/testing/Makefile      |   2 -
 kernel/drivers/analogy/testing/fake.c        |   6 +-
 kernel/drivers/analogy/testing/loop.c        | 285 -------------------
 kernel/drivers/net/drivers/eepro100.c        |   6 +-
 kernel/drivers/net/stack/rtcfg/rtcfg_frame.c |  21 +-
 6 files changed, 22 insertions(+), 301 deletions(-)
 delete mode 100644 kernel/drivers/analogy/testing/loop.c
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH 3/5 drivers/analogy/testing: Resolve FORTIFY_SOURCE warning

From: Jan Kiszka <[email protected]>

Convert the private field to the right type so that we can avoid memcpy and rather set a pointer to the shared private buffer.

---
 kernel/drivers/analogy/testing/fake.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/drivers/analogy/testing/fake.c +3 -3
index cae0998be5..fd88ed99f9 100644
@@ -555,8 +555,8 @@ static int test_attach(struct a4l_device *dev, a4l_lnkdesc_t *arg)
 {
 	typedef void (*setup_subd_function) (struct a4l_subdevice *subd);
 	struct fake_priv *priv = (struct fake_priv *) dev->priv;
+	struct ao_ai2_priv **priv_ptr;
 	struct a4l_subdevice *subd;
-	unsigned long tmp;
 	struct ai_priv *r;
 	int i, ret = 0;
 
@@ -632,8 +632,8 @@ static int test_attach(struct a4l_device *dev, a4l_lnkdesc_t *arg)
 	r->quanta_cnt = priv->quanta_cnt;
 
 	/* A0 and AI2 shared their private buffers */
-	tmp = (unsigned long) sds[AO_SUBD].subd->priv;
-	memcpy(sds[AI2_SUBD].subd->priv, &tmp, sds[AI2_SUBD].private_len) ;
+	priv_ptr = (struct ao_ai2_priv **)sds[AI2_SUBD].subd->priv;
+	*priv_ptr = (struct ao_ai2_priv *)sds[AO_SUBD].subd->priv;
 
 	/* create the task */
 	ret = rtdm_task_init(&priv->task, "Fake AI task", task_proc, dev,
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH 4/5 drivers/net/eepro100: Silence FORTIFY_SOURCE warning

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

We are writing into correctly allocated areas in the TX ring in both cases.

---
 kernel/drivers/net/drivers/eepro100.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/drivers/net/drivers/eepro100.c +4 -2
index e889894464..40bb1dd7ec 100644
@@ -997,7 +997,8 @@ static void speedo_resume(struct rtnet_device *rtdev)
 		ias_cmd->cmd_status = cpu_to_le32((CmdSuspend | CmdIASetup) | 0xa000);
 		ias_cmd->link =
 			cpu_to_le32(TX_RING_ELEM_DMA(sp, sp->cur_tx % TX_RING_SIZE));
-		memcpy(ias_cmd->params, rtdev->dev_addr, 6);
+		memcpy(((u8 *)ias_cmd) + offsetof(struct descriptor, params),
+		       rtdev->dev_addr, 6);
 		sp->last_cmd = ias_cmd;
 	}
 
@@ -1705,7 +1706,8 @@ static void set_rx_mode(struct rtnet_device *rtdev)
 		sp->tx_ring[entry].status = cpu_to_le32(CmdSuspend | CmdConfigure);
 		sp->tx_ring[entry].link =
 			cpu_to_le32(TX_RING_ELEM_DMA(sp, (entry + 1) % TX_RING_SIZE));
-		config_cmd_data = (void *)&sp->tx_ring[entry].tx_desc_addr;
+		config_cmd_data = ((u8 *)&sp->tx_ring[entry]) +
+			offsetof(struct TxFD, tx_desc_addr);
 		/* Construct a full CmdConfig frame. */
 		memcpy(config_cmd_data, i82558_config_cmd, CONFIG_DATA_SIZE);
 		config_cmd_data[1] = (txfifo << 4) | rxfifo;
Signature · 1 line
2.43.0