openwrt-packages/libs/libpfring/patches/101-kernel-pf_ring-better-d...

73 lines
2.3 KiB
Diff

From fae2437c2af80d3ea64f5bc9678a5b697772295b Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Mon, 18 Mar 2024 10:03:43 +0100
Subject: [PATCH] kernel: pf_ring: better define sa_data size
pfring_mod_bind() needs to specify the interface
name using struct sockaddr that is defined as
struct sockaddr { ushort sa_family; char sa_data[14]; };
so the total interface name length is 13 chars (plus \0 trailer).
Since sa_data size is arbitrary, define a more precise size for
PF_RING socket use.
This fix some compilation error with fortify string and makes the array
handling more deterministic.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
kernel/pf_ring.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
--- a/kernel/pf_ring.c
+++ b/kernel/pf_ring.c
@@ -155,6 +155,18 @@
#endif
#endif
+/*
+ pfring_mod_bind() needs to specify the interface
+ name using struct sockaddr that is defined as
+
+ struct sockaddr { ushort sa_family; char sa_data[14]; };
+
+ so the total interface name length is 13 chars (plus \0 trailer).
+ Since sa_data size is arbitrary, define a more precise size for
+ PF_RING socket use.
+*/
+#define RING_SA_DATA_LEN 14
+
/* ************************************************* */
#if(LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
@@ -1029,7 +1041,7 @@ pf_ring_device *pf_ring_device_name_look
so the total interface name length is 13 chars (plus \0 trailer).
The check below is to trap this case.
*/
- || ((l >= 13) && (strncmp(dev_ptr->device_name, name, 13) == 0)))
+ || ((l >= RING_SA_DATA_LEN - 1) && (strncmp(dev_ptr->device_name, name, RING_SA_DATA_LEN - 1) == 0)))
&& device_net_eq(dev_ptr, net))
return dev_ptr;
}
@@ -5571,15 +5583,15 @@ static int ring_bind(struct socket *sock
* Check legality
*/
if (addr_len == sizeof(struct sockaddr)) {
- char name[sizeof(sa->sa_data)+1];
+ char name[RING_SA_DATA_LEN];
if (sa->sa_family != PF_RING)
return(-EINVAL);
- memcpy(name, sa->sa_data, sizeof(sa->sa_data));
+ memcpy(name, sa->sa_data, RING_SA_DATA_LEN - 1);
/* Add trailing zero if missing */
- name[sizeof(name)-1] = '\0';
+ name[RING_SA_DATA_LEN-1] = '\0';
debug_printk(2, "searching device %s\n", name);