aboutsummaryrefslogtreecommitdiff
path: root/libs/libpfring/patches/101-kernel-pf_ring-better-define-sa_data-size.patch
blob: 7c27515f4c0a7b8266d1bff40f281e98b090d2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);