Skip to content

Commit

Permalink
net: core: improve sanity checking in __dev_alloc_name
Browse files Browse the repository at this point in the history
__dev_alloc_name is called from the public (and exported)
dev_alloc_name(), so we don't have a guarantee that strlen(name) is at
most IFNAMSIZ. If somebody manages to get __dev_alloc_name called with a
% char beyond the 31st character, we'd be making a snprintf() call that
will very easily crash the kernel (using an appropriate %p extension,
we'll likely dereference some completely bogus pointer).

In the normal case where strlen() is sane, we don't even save anything
by limiting to IFNAMSIZ, so just use strchr().

Signed-off-by: Rasmus Villemoes <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Villemoes authored and davem330 committed Nov 14, 2017
1 parent 951b796 commit 51f299d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
unsigned long *inuse;
struct net_device *d;

p = strnchr(name, IFNAMSIZ-1, '%');
p = strchr(name, '%');
if (p) {
/*
* Verify the string as this thing may have come from
Expand Down

0 comments on commit 51f299d

Please sign in to comment.