Skip to contentSkip to conversation

sandbox: prevent segfault in tap_alloc()

RFC In review Antony Pavlov 2 participants 4 messages Jun 19, 2019 – Jun 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 sandbox: prevent segfault in tap_alloc()

Tap network interface initialization in sandbox barebox leads to segfault under Debian Buster/Sid.

The problem is that strcpy(dev, ifr.ifr_name) inside tap_alloc() tries to alter read-only data passed by tap_probe() and barebox receives SIGSEGV.

---
 drivers/net/tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/tap.c +2 -2
index 1fbfa085b1..d7e32f4875 100644
@@ -14,7 +14,7 @@
 
 struct tap_priv {
 	int fd;
-	char *name;
+	char name[128];
 };
 
 static int tap_eth_send(struct eth_device *edev, void *packet, int length)
@@ -65,7 +65,7 @@ static int tap_probe(struct device_d *dev)
 	int ret = 0;
 
 	priv = xzalloc(sizeof(struct tap_priv));
-	priv->name = "barebox";
+	strncpy(priv->name, "barebox", sizeof(priv->name));
 
 	priv->fd = tap_alloc(priv->name);
 	if (priv->fd < 0) {
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Antony,

Quoted 26 lines · Antony Pavlov

Tap network interface initialization in sandbox barebox leads to segfault under Debian Buster/Sid.

The problem is that strcpy(dev, ifr.ifr_name) inside tap_alloc() tries to alter read-only data passed by tap_probe() and barebox receives SIGSEGV.

---
 drivers/net/tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/tap.c +1 -1
index 1fbfa085b1..d7e32f4875 100644
@@ -14,7 +14,7 @@
 
 struct tap_priv {
 	int fd;
-	char *name;
+	char name[128];
 };
 
 static int tap_eth_send(struct eth_device *edev, void *packet, int length)

drivers/net/tap.c static int tap_probe(struct device_d *dev) · line 70

Quoted 7 lines
drivers/net/tap.c +1 -1
@@ -65,7 +65,7 @@ static int tap_probe(struct device_d *dev)
 	int ret = 0;
 
 	priv = xzalloc(sizeof(struct tap_priv));
-	priv->name = "barebox";
+	strncpy(priv->name, "barebox", sizeof(priv->name));
 
 	priv->fd = tap_alloc(priv->name);

Can we change the prototype of tap_alloc() to something like this:

int tap_alloc(const char *name, int *fd, char **outname);

outname would be an allocated string to be freed by the caller.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
Quoted 35 lines · On Wed, 26 Jun 2019 09:12:02 +0200 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 32 lines · Antony Pavlov

Tap network interface initialization in sandbox barebox leads to segfault under Debian Buster/Sid.

The problem is that strcpy(dev, ifr.ifr_name) inside tap_alloc() tries to alter read-only data passed by tap_probe() and barebox receives SIGSEGV.

---
 drivers/net/tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/tap.c +2 -2
index 1fbfa085b1..d7e32f4875 100644
@@ -14,7 +14,7 @@
 
 struct tap_priv {
 	int fd;
-	char *name;
+	char name[128];
 };
 
 static int tap_eth_send(struct eth_device *edev, void *packet, int length)
@@ -65,7 +65,7 @@ static int tap_probe(struct device_d *dev)
 	int ret = 0;
 
 	priv = xzalloc(sizeof(struct tap_priv));
-	priv->name = "barebox";
+	strncpy(priv->name, "barebox", sizeof(priv->name));
 
Quoted 7 lines

drivers/net/tap.c static int tap_probe(struct device_d *dev) · line 70

Quoted 1 line
drivers/net/tap.c +0 -0
 	priv->fd = tap_alloc(priv->name);

Can we change the prototype of tap_alloc() to something like this:

int tap_alloc(const char *name, int *fd, char **outname);

outname would be an allocated string to be freed by the caller.

There is one problem.
tap_alloc works in the sandbox "os domain" (glibc *alloc&free etc), the caller works in the "barebox domain" (barebox *alloc&free).

Can we just drop this outname?
nobody actually use it at the moment.

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
Quoted 42 lines · Antony Pavlov
Quoted 39 lines · On Wed, 26 Jun 2019 09:12:02 +0200 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 26 lines · Antony Pavlov

Tap network interface initialization in sandbox barebox leads to segfault under Debian Buster/Sid.

The problem is that strcpy(dev, ifr.ifr_name) inside tap_alloc() tries to alter read-only data passed by tap_probe() and barebox receives SIGSEGV.

---
 drivers/net/tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/tap.c +1 -1
index 1fbfa085b1..d7e32f4875 100644
@@ -14,7 +14,7 @@
 
 struct tap_priv {
 	int fd;
-	char *name;
+	char name[128];
 };
 
 static int tap_eth_send(struct eth_device *edev, void *packet, int length)

drivers/net/tap.c static int tap_probe(struct device_d *dev) · line 70

Quoted 7 lines
drivers/net/tap.c +1 -1
@@ -65,7 +65,7 @@ static int tap_probe(struct device_d *dev)
 	int ret = 0;
 
 	priv = xzalloc(sizeof(struct tap_priv));
-	priv->name = "barebox";
+	strncpy(priv->name, "barebox", sizeof(priv->name));
 
 	priv->fd = tap_alloc(priv->name);

Can we change the prototype of tap_alloc() to something like this:

Quoted 7 lines
Quoted 3 lines

int tap_alloc(const char *name, int *fd, char **outname);

outname would be an allocated string to be freed by the caller.

There is one problem.
tap_alloc works in the sandbox "os domain" (glibc *alloc&free etc), the caller works in the "barebox domain" (barebox *alloc&free).

Oh, I didn't realize this.

Quoted 3 lines

Can we just drop this outname?
nobody actually use it at the moment.

Yes, let's just drop it.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox