Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1699884 > unrolled thread
| Started by | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| First post | 2017-07-31 12:10 +0200 |
| Last post | 2017-08-01 11:30 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] netfilter: fix stringop-overflow warning with UBSAN Arnd Bergmann <arnd@arndb.de> - 2017-07-31 12:10 +0200
RE: [PATCH] netfilter: fix stringop-overflow warning with UBSAN David Laight <David.Laight@ACULAB.COM> - 2017-08-01 11:30 +0200
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2017-07-31 12:10 +0200 |
| Subject | [PATCH] netfilter: fix stringop-overflow warning with UBSAN |
| Message-ID | <u9fOb-4XH-35@gated-at.bofh.it> |
Using gcc-7 with UBSAN enabled, we get this false-positive warning:
net/netfilter/ipset/ip_set_core.c: In function 'ip_set_sockfn_get':
net/netfilter/ipset/ip_set_core.c:1998:3: error: 'strncpy' writing 32 bytes into a region of size 2 overflows the destination [-Werror=stringop-overflow=]
strncpy(req_get->set.name, set ? set->name : "",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sizeof(req_get->set.name));
~~~~~~~~~~~~~~~~~~~~~~~~~~
This seems completely bogus, and I could not find a nice workaround.
To work around it in a less elegant way, I change the ?: operator
into an if()/else() construct.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
net/netfilter/ipset/ip_set_core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index e495b5e484b1..d7ebb021003b 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -1995,8 +1995,12 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
}
nfnl_lock(NFNL_SUBSYS_IPSET);
set = ip_set(inst, req_get->set.index);
- strncpy(req_get->set.name, set ? set->name : "",
- IPSET_MAXNAMELEN);
+ if (set)
+ strncpy(req_get->set.name, set->name,
+ sizeof(req_get->set.name));
+ else
+ memset(req_get->set.name, '\0',
+ sizeof(req_get->set.name));
nfnl_unlock(NFNL_SUBSYS_IPSET);
goto copy;
}
--
2.9.0
[toc] | [next] | [standalone]
| From | David Laight <David.Laight@ACULAB.COM> |
|---|---|
| Date | 2017-08-01 11:30 +0200 |
| Message-ID | <u9BEZ-1GX-5@gated-at.bofh.it> |
| In reply to | #1699884 |
From: Arnd Bergmann > Sent: 31 July 2017 11:09 > Using gcc-7 with UBSAN enabled, we get this false-positive warning: > > net/netfilter/ipset/ip_set_core.c: In function 'ip_set_sockfn_get': > net/netfilter/ipset/ip_set_core.c:1998:3: error: 'strncpy' writing 32 bytes into a region of size 2 > overflows the destination [-Werror=stringop-overflow=] > strncpy(req_get->set.name, set ? set->name : "", > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > sizeof(req_get->set.name)); > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > This seems completely bogus, and I could not find a nice workaround. > To work around it in a less elegant way, I change the ?: operator > into an if()/else() construct. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > net/netfilter/ipset/ip_set_core.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c > index e495b5e484b1..d7ebb021003b 100644 > --- a/net/netfilter/ipset/ip_set_core.c > +++ b/net/netfilter/ipset/ip_set_core.c > @@ -1995,8 +1995,12 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len) > } > nfnl_lock(NFNL_SUBSYS_IPSET); > set = ip_set(inst, req_get->set.index); > - strncpy(req_get->set.name, , > - IPSET_MAXNAMELEN); > + if (set) > + strncpy(req_get->set.name, set->name, > + sizeof(req_get->set.name)); > + else > + memset(req_get->set.name, '\0', > + sizeof(req_get->set.name)); If you use strncpy() here, the compiler might optimise the code back to 'how it was before'. Or, maybe an explicit temporary: 'const char *name = set ? set->name : ""; David
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web