* [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG
@ 2017-10-23 18:16 Gustavo A. R. Silva
[not found] ` <20171023181635.GA25334-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-23 18:16 UTC (permalink / raw)
To: J. Bruce Fields, Jeff Layton, Trond Myklebust, Anna Schumaker,
David S. Miller
Cc: linux-nfs, netdev, linux-kernel, Gustavo A. R. Silva
Use BUG_ON instead of if condition followed by BUG.
This issue was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
net/sunrpc/auth_gss/svcauth_gss.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 7b1ee5a..a10ce43 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -855,11 +855,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g
return stat;
if (integ_len > buf->len)
return stat;
- if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len))
- BUG();
+ BUG_ON(xdr_buf_subsegment(buf, &integ_buf, 0, integ_len));
/* copy out mic... */
- if (read_u32_from_xdr_buf(buf, integ_len, &mic.len))
- BUG();
+ BUG_ON(read_u32_from_xdr_buf(buf, integ_len, &mic.len));
if (mic.len > RPC_MAX_AUTH_SIZE)
return stat;
mic.data = kmalloc(mic.len, GFP_KERNEL);
@@ -1611,8 +1609,7 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp)
BUG_ON(integ_len % 4);
*p++ = htonl(integ_len);
*p++ = htonl(gc->gc_seq);
- if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len))
- BUG();
+ BUG_ON(xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len));
if (resbuf->tail[0].iov_base == NULL) {
if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE)
goto out_err;
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread[parent not found: <20171023181635.GA25334-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org>]
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG [not found] ` <20171023181635.GA25334-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org> @ 2017-10-23 20:31 ` J. Bruce Fields 2017-10-24 17:26 ` Weston Andros Adamson 0 siblings, 1 reply; 8+ messages in thread From: J. Bruce Fields @ 2017-10-23 20:31 UTC (permalink / raw) To: Gustavo A. R. Silva Cc: Jeff Layton, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA In the past we've avoided BUG_ON(X) where X might have side effects, on the theory that it should actually be OK just to compile out BUG_ON()s. Has that changed? In any case, I don't find that this improves readability; dropping. --b. On Mon, Oct 23, 2017 at 01:16:35PM -0500, Gustavo A. R. Silva wrote: > Use BUG_ON instead of if condition followed by BUG. > > This issue was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva <garsilva-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org> > --- > net/sunrpc/auth_gss/svcauth_gss.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c > index 7b1ee5a..a10ce43 100644 > --- a/net/sunrpc/auth_gss/svcauth_gss.c > +++ b/net/sunrpc/auth_gss/svcauth_gss.c > @@ -855,11 +855,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g > return stat; > if (integ_len > buf->len) > return stat; > - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) > - BUG(); > + BUG_ON(xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)); > /* copy out mic... */ > - if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) > - BUG(); > + BUG_ON(read_u32_from_xdr_buf(buf, integ_len, &mic.len)); > if (mic.len > RPC_MAX_AUTH_SIZE) > return stat; > mic.data = kmalloc(mic.len, GFP_KERNEL); > @@ -1611,8 +1609,7 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) > BUG_ON(integ_len % 4); > *p++ = htonl(integ_len); > *p++ = htonl(gc->gc_seq); > - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) > - BUG(); > + BUG_ON(xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)); > if (resbuf->tail[0].iov_base == NULL) { > if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) > goto out_err; > -- > 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG 2017-10-23 20:31 ` J. Bruce Fields @ 2017-10-24 17:26 ` Weston Andros Adamson [not found] ` <496D700A-E9D1-4745-B5DE-24BB9231A449-J6AcJDG0ZEwdnm+yROfE0A@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Weston Andros Adamson @ 2017-10-24 17:26 UTC (permalink / raw) To: J. Bruce Fields Cc: Gustavo A. R. Silva, Jeff Layton, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs list, netdev, linux-kernel@vger.kernel.org Is there a reason to BUG() in these places? Couldn't we WARN_ON_ONCE and return an error? -dros > On Oct 23, 2017, at 4:31 PM, J. Bruce Fields <bfields@fieldses.org> wrote: > > In the past we've avoided BUG_ON(X) where X might have side effects, on > the theory that it should actually be OK just to compile out BUG_ON()s. > Has that changed? > > In any case, I don't find that this improves readability; dropping. > > --b. > > On Mon, Oct 23, 2017 at 01:16:35PM -0500, Gustavo A. R. Silva wrote: >> Use BUG_ON instead of if condition followed by BUG. >> >> This issue was detected with the help of Coccinelle. >> >> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> >> --- >> net/sunrpc/auth_gss/svcauth_gss.c | 9 +++------ >> 1 file changed, 3 insertions(+), 6 deletions(-) >> >> diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c >> index 7b1ee5a..a10ce43 100644 >> --- a/net/sunrpc/auth_gss/svcauth_gss.c >> +++ b/net/sunrpc/auth_gss/svcauth_gss.c >> @@ -855,11 +855,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g >> return stat; >> if (integ_len > buf->len) >> return stat; >> - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) >> - BUG(); >> + BUG_ON(xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)); >> /* copy out mic... */ >> - if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) >> - BUG(); >> + BUG_ON(read_u32_from_xdr_buf(buf, integ_len, &mic.len)); >> if (mic.len > RPC_MAX_AUTH_SIZE) >> return stat; >> mic.data = kmalloc(mic.len, GFP_KERNEL); >> @@ -1611,8 +1609,7 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) >> BUG_ON(integ_len % 4); >> *p++ = htonl(integ_len); >> *p++ = htonl(gc->gc_seq); >> - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) >> - BUG(); >> + BUG_ON(xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)); >> if (resbuf->tail[0].iov_base == NULL) { >> if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) >> goto out_err; >> -- >> 2.7.4 > -- > To unsubscribe from this list: send the line "unsubscribe linux-nfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <496D700A-E9D1-4745-B5DE-24BB9231A449-J6AcJDG0ZEwdnm+yROfE0A@public.gmane.org>]
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG [not found] ` <496D700A-E9D1-4745-B5DE-24BB9231A449-J6AcJDG0ZEwdnm+yROfE0A@public.gmane.org> @ 2017-10-24 17:53 ` J. Bruce Fields 2017-10-24 18:18 ` Jeff Layton 0 siblings, 1 reply; 8+ messages in thread From: J. Bruce Fields @ 2017-10-24 17:53 UTC (permalink / raw) To: Weston Andros Adamson Cc: Gustavo A. R. Silva, Jeff Layton, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs list, netdev-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org On Tue, Oct 24, 2017 at 01:26:49PM -0400, Weston Andros Adamson wrote: > Is there a reason to BUG() in these places? Couldn't we WARN_ON_ONCE and return an error? I think the BUG() will just kill an nfsd thread that isn't holding any interesting locks. The failures look unlikely. (Except for that read_u32... return, I wonder if we're missing a check there.) --b. > > -dros > > > On Oct 23, 2017, at 4:31 PM, J. Bruce Fields <bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org> wrote: > > > > In the past we've avoided BUG_ON(X) where X might have side effects, on > > the theory that it should actually be OK just to compile out BUG_ON()s. > > Has that changed? > > > > In any case, I don't find that this improves readability; dropping. > > > > --b. > > > > On Mon, Oct 23, 2017 at 01:16:35PM -0500, Gustavo A. R. Silva wrote: > >> Use BUG_ON instead of if condition followed by BUG. > >> > >> This issue was detected with the help of Coccinelle. > >> > >> Signed-off-by: Gustavo A. R. Silva <garsilva-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org> > >> --- > >> net/sunrpc/auth_gss/svcauth_gss.c | 9 +++------ > >> 1 file changed, 3 insertions(+), 6 deletions(-) > >> > >> diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c > >> index 7b1ee5a..a10ce43 100644 > >> --- a/net/sunrpc/auth_gss/svcauth_gss.c > >> +++ b/net/sunrpc/auth_gss/svcauth_gss.c > >> @@ -855,11 +855,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g > >> return stat; > >> if (integ_len > buf->len) > >> return stat; > >> - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) > >> - BUG(); > >> + BUG_ON(xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)); > >> /* copy out mic... */ > >> - if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) > >> - BUG(); > >> + BUG_ON(read_u32_from_xdr_buf(buf, integ_len, &mic.len)); > >> if (mic.len > RPC_MAX_AUTH_SIZE) > >> return stat; > >> mic.data = kmalloc(mic.len, GFP_KERNEL); > >> @@ -1611,8 +1609,7 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) > >> BUG_ON(integ_len % 4); > >> *p++ = htonl(integ_len); > >> *p++ = htonl(gc->gc_seq); > >> - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) > >> - BUG(); > >> + BUG_ON(xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)); > >> if (resbuf->tail[0].iov_base == NULL) { > >> if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) > >> goto out_err; > >> -- > >> 2.7.4 > > -- > > To unsubscribe from this list: send the line "unsubscribe linux-nfs" in > > the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG 2017-10-24 17:53 ` J. Bruce Fields @ 2017-10-24 18:18 ` Jeff Layton 2017-10-24 19:07 ` J. Bruce Fields 0 siblings, 1 reply; 8+ messages in thread From: Jeff Layton @ 2017-10-24 18:18 UTC (permalink / raw) To: J. Bruce Fields, Weston Andros Adamson Cc: Gustavo A. R. Silva, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs list, netdev, linux-kernel@vger.kernel.org On Tue, 2017-10-24 at 13:53 -0400, J. Bruce Fields wrote: > On Tue, Oct 24, 2017 at 01:26:49PM -0400, Weston Andros Adamson wrote: > > Is there a reason to BUG() in these places? Couldn't we WARN_ON_ONCE and return an error? > > I think the BUG() will just kill an nfsd thread that isn't holding any > interesting locks. > Not necessarily. If panic_on_oops is set (and it usually is in "production" setups), it'll crash the box there. > The failures look unlikely. (Except for that read_u32... return, I > wonder if we're missing a check there.) > Agreed, looks like you only hit an error if the read attempts to go out of bounds. In principle that shouldn't ever happen (and I haven't seen any reports of it). Still...I agree with Dros that it's better to handle this without oopsing if we can. We can return an error from either of those functions. A sane error and a WARN_ONCE would be better here. > --b. > > > > > -dros > > > > > On Oct 23, 2017, at 4:31 PM, J. Bruce Fields <bfields@fieldses.org> wrote: > > > > > > In the past we've avoided BUG_ON(X) where X might have side effects, on > > > the theory that it should actually be OK just to compile out BUG_ON()s. > > > Has that changed? > > > > > > In any case, I don't find that this improves readability; dropping. > > > > > > --b. > > > > > > On Mon, Oct 23, 2017 at 01:16:35PM -0500, Gustavo A. R. Silva wrote: > > > > Use BUG_ON instead of if condition followed by BUG. > > > > > > > > This issue was detected with the help of Coccinelle. > > > > > > > > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> > > > > --- > > > > net/sunrpc/auth_gss/svcauth_gss.c | 9 +++------ > > > > 1 file changed, 3 insertions(+), 6 deletions(-) > > > > > > > > diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c > > > > index 7b1ee5a..a10ce43 100644 > > > > --- a/net/sunrpc/auth_gss/svcauth_gss.c > > > > +++ b/net/sunrpc/auth_gss/svcauth_gss.c > > > > @@ -855,11 +855,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g > > > > return stat; > > > > if (integ_len > buf->len) > > > > return stat; > > > > - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) > > > > - BUG(); > > > > + BUG_ON(xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)); > > > > /* copy out mic... */ > > > > - if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) > > > > - BUG(); > > > > + BUG_ON(read_u32_from_xdr_buf(buf, integ_len, &mic.len)); > > > > if (mic.len > RPC_MAX_AUTH_SIZE) > > > > return stat; > > > > mic.data = kmalloc(mic.len, GFP_KERNEL); > > > > @@ -1611,8 +1609,7 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) > > > > BUG_ON(integ_len % 4); > > > > *p++ = htonl(integ_len); > > > > *p++ = htonl(gc->gc_seq); > > > > - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) > > > > - BUG(); > > > > + BUG_ON(xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)); > > > > if (resbuf->tail[0].iov_base == NULL) { > > > > if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) > > > > goto out_err; > > > > -- > > > > 2.7.4 > > > > > > -- > > > To unsubscribe from this list: send the line "unsubscribe linux-nfs" in > > > the body of a message to majordomo@vger.kernel.org > > > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Jeff Layton <jlayton@redhat.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG 2017-10-24 18:18 ` Jeff Layton @ 2017-10-24 19:07 ` J. Bruce Fields 2017-10-24 20:12 ` Gustavo A. R. Silva 0 siblings, 1 reply; 8+ messages in thread From: J. Bruce Fields @ 2017-10-24 19:07 UTC (permalink / raw) To: Jeff Layton Cc: Weston Andros Adamson, Gustavo A. R. Silva, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs list, netdev, linux-kernel@vger.kernel.org On Tue, Oct 24, 2017 at 02:18:52PM -0400, Jeff Layton wrote: > On Tue, 2017-10-24 at 13:53 -0400, J. Bruce Fields wrote: > > On Tue, Oct 24, 2017 at 01:26:49PM -0400, Weston Andros Adamson wrote: > > > Is there a reason to BUG() in these places? Couldn't we WARN_ON_ONCE and return an error? > > > > I think the BUG() will just kill an nfsd thread that isn't holding any > > interesting locks. > > > > Not necessarily. If panic_on_oops is set (and it usually is in > "production" setups), it'll crash the box there. Maybe they're getting what they asked for? > > The failures look unlikely. (Except for that read_u32... return, I > > wonder if we're missing a check there.) > > Agreed, looks like you only hit an error if the read attempts to go out > of bounds. In principle that shouldn't ever happen (and I haven't seen > any reports of it). > > Still...I agree with Dros that it's better to handle this without > oopsing if we can. We can return an error from either of those > functions. A sane error and a WARN_ONCE would be better here. OK, OK, OK. There are also some more BUGs that could use looking into if anyone wants to. --b. commit eb754930662f Author: J. Bruce Fields <bfields@redhat.com> Date: Tue Oct 24 14:58:11 2017 -0400 rpc: remove some BUG()s It would be kinder to WARN() and recover in several spots here instead of BUG()ing. Also, it looks like the read_u32_from_xdr_buf() call could actually fail, though it might require a broken (or malicious) client, so convert that to just an error return. Reported-by: Weston Andros Adamson <dros@monkey.org> Signed-off-by: J. Bruce Fields <bfields@redhat.com> diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 7b1ee5a0b03c..73165e9ca5bf 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -855,11 +855,13 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g return stat; if (integ_len > buf->len) return stat; - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) - BUG(); + if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) { + WARN_ON_ONCE(1); + return stat; + } /* copy out mic... */ if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) - BUG(); + return stat; if (mic.len > RPC_MAX_AUTH_SIZE) return stat; mic.data = kmalloc(mic.len, GFP_KERNEL); @@ -1611,8 +1613,10 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) BUG_ON(integ_len % 4); *p++ = htonl(integ_len); *p++ = htonl(gc->gc_seq); - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) - BUG(); + if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) { + WARN_ON_ONCE(1); + goto out_err; + } if (resbuf->tail[0].iov_base == NULL) { if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) goto out_err; ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG 2017-10-24 19:07 ` J. Bruce Fields @ 2017-10-24 20:12 ` Gustavo A. R. Silva 2017-10-25 17:04 ` Jeff Layton 0 siblings, 1 reply; 8+ messages in thread From: Gustavo A. R. Silva @ 2017-10-24 20:12 UTC (permalink / raw) To: J. Bruce Fields Cc: Jeff Layton, Weston Andros Adamson, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs list, netdev, linux-kernel Quoting "J. Bruce Fields" <bfields@fieldses.org>: > On Tue, Oct 24, 2017 at 02:18:52PM -0400, Jeff Layton wrote: >> On Tue, 2017-10-24 at 13:53 -0400, J. Bruce Fields wrote: >> > On Tue, Oct 24, 2017 at 01:26:49PM -0400, Weston Andros Adamson wrote: >> > > Is there a reason to BUG() in these places? Couldn't we >> WARN_ON_ONCE and return an error? >> > >> > I think the BUG() will just kill an nfsd thread that isn't holding any >> > interesting locks. >> > >> >> Not necessarily. If panic_on_oops is set (and it usually is in >> "production" setups), it'll crash the box there. > > Maybe they're getting what they asked for? > >> > The failures look unlikely. (Except for that read_u32... return, I >> > wonder if we're missing a check there.) >> >> Agreed, looks like you only hit an error if the read attempts to go out >> of bounds. In principle that shouldn't ever happen (and I haven't seen >> any reports of it). >> >> Still...I agree with Dros that it's better to handle this without >> oopsing if we can. We can return an error from either of those >> functions. A sane error and a WARN_ONCE would be better here. > > OK, OK, OK. > > There are also some more BUGs that could use looking into if anyone > wants to. > > --b. > > commit eb754930662f > Author: J. Bruce Fields <bfields@redhat.com> > Date: Tue Oct 24 14:58:11 2017 -0400 > > rpc: remove some BUG()s > > It would be kinder to WARN() and recover in several spots here instead > of BUG()ing. > > Also, it looks like the read_u32_from_xdr_buf() call could actually > fail, though it might require a broken (or malicious) client, so convert > that to just an error return. > > Reported-by: Weston Andros Adamson <dros@monkey.org> > Signed-off-by: J. Bruce Fields <bfields@redhat.com> > > diff --git a/net/sunrpc/auth_gss/svcauth_gss.c > b/net/sunrpc/auth_gss/svcauth_gss.c > index 7b1ee5a0b03c..73165e9ca5bf 100644 > --- a/net/sunrpc/auth_gss/svcauth_gss.c > +++ b/net/sunrpc/auth_gss/svcauth_gss.c > @@ -855,11 +855,13 @@ unwrap_integ_data(struct svc_rqst *rqstp, > struct xdr_buf *buf, u32 seq, struct g > return stat; > if (integ_len > buf->len) > return stat; > - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) > - BUG(); > + if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) { > + WARN_ON_ONCE(1); > + return stat; > + } > /* copy out mic... */ > if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) > - BUG(); > + return stat; > if (mic.len > RPC_MAX_AUTH_SIZE) > return stat; > mic.data = kmalloc(mic.len, GFP_KERNEL); > @@ -1611,8 +1613,10 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) > BUG_ON(integ_len % 4); > *p++ = htonl(integ_len); > *p++ = htonl(gc->gc_seq); > - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) > - BUG(); > + if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) { > + WARN_ON_ONCE(1); > + goto out_err; > + } > if (resbuf->tail[0].iov_base == NULL) { > if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) > goto out_err; What about the following BUG() at net/sunrpc/svc_xprt.c:1058: /* * Remove a dead transport */ static void svc_delete_xprt(struct svc_xprt *xprt) { struct svc_serv *serv = xprt->xpt_server; struct svc_deferred_req *dr; /* Only do this once */ if (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) BUG(); dprintk("svc: svc_delete_xprt(%p)\n", xprt); xprt->xpt_ops->xpo_detach(xprt); spin_lock_bh(&serv->sv_lock); list_del_init(&xprt->xpt_list); WARN_ON_ONCE(!list_empty(&xprt->xpt_ready)); if (test_bit(XPT_TEMP, &xprt->xpt_flags)) serv->sv_tmpcnt--; spin_unlock_bh(&serv->sv_lock); while ((dr = svc_deferred_dequeue(xprt)) != NULL) kfree(dr); call_xpt_users(xprt); svc_xprt_put(xprt); } I'm suspicious about that comment above the _if_ condition: /* Only do this once */ Would it help to replace that BUG with a WARN_ON_ONCE? Thanks ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG 2017-10-24 20:12 ` Gustavo A. R. Silva @ 2017-10-25 17:04 ` Jeff Layton 0 siblings, 0 replies; 8+ messages in thread From: Jeff Layton @ 2017-10-25 17:04 UTC (permalink / raw) To: Gustavo A. R. Silva, J. Bruce Fields Cc: Weston Andros Adamson, Trond Myklebust, Anna Schumaker, David S. Miller, linux-nfs list, netdev, linux-kernel On Tue, 2017-10-24 at 15:12 -0500, Gustavo A. R. Silva wrote: > Quoting "J. Bruce Fields" <bfields@fieldses.org>: > > > On Tue, Oct 24, 2017 at 02:18:52PM -0400, Jeff Layton wrote: > > > On Tue, 2017-10-24 at 13:53 -0400, J. Bruce Fields wrote: > > > > On Tue, Oct 24, 2017 at 01:26:49PM -0400, Weston Andros Adamson wrote: > > > > > Is there a reason to BUG() in these places? Couldn't we > > > > > > WARN_ON_ONCE and return an error? > > > > > > > > I think the BUG() will just kill an nfsd thread that isn't holding any > > > > interesting locks. > > > > > > > > > > Not necessarily. If panic_on_oops is set (and it usually is in > > > "production" setups), it'll crash the box there. > > > > Maybe they're getting what they asked for? > > > > > > The failures look unlikely. (Except for that read_u32... return, I > > > > wonder if we're missing a check there.) > > > > > > Agreed, looks like you only hit an error if the read attempts to go out > > > of bounds. In principle that shouldn't ever happen (and I haven't seen > > > any reports of it). > > > > > > Still...I agree with Dros that it's better to handle this without > > > oopsing if we can. We can return an error from either of those > > > functions. A sane error and a WARN_ONCE would be better here. > > > > OK, OK, OK. > > > > There are also some more BUGs that could use looking into if anyone > > wants to. > > > > --b. > > > > commit eb754930662f > > Author: J. Bruce Fields <bfields@redhat.com> > > Date: Tue Oct 24 14:58:11 2017 -0400 > > > > rpc: remove some BUG()s > > > > It would be kinder to WARN() and recover in several spots here instead > > of BUG()ing. > > > > Also, it looks like the read_u32_from_xdr_buf() call could actually > > fail, though it might require a broken (or malicious) client, so convert > > that to just an error return. > > > > Reported-by: Weston Andros Adamson <dros@monkey.org> > > Signed-off-by: J. Bruce Fields <bfields@redhat.com> > > > > diff --git a/net/sunrpc/auth_gss/svcauth_gss.c > > b/net/sunrpc/auth_gss/svcauth_gss.c > > index 7b1ee5a0b03c..73165e9ca5bf 100644 > > --- a/net/sunrpc/auth_gss/svcauth_gss.c > > +++ b/net/sunrpc/auth_gss/svcauth_gss.c > > @@ -855,11 +855,13 @@ unwrap_integ_data(struct svc_rqst *rqstp, > > struct xdr_buf *buf, u32 seq, struct g > > return stat; > > if (integ_len > buf->len) > > return stat; > > - if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) > > - BUG(); > > + if (xdr_buf_subsegment(buf, &integ_buf, 0, integ_len)) { > > + WARN_ON_ONCE(1); > > + return stat; > > + } > > /* copy out mic... */ > > if (read_u32_from_xdr_buf(buf, integ_len, &mic.len)) > > - BUG(); > > + return stat; > > if (mic.len > RPC_MAX_AUTH_SIZE) > > return stat; > > mic.data = kmalloc(mic.len, GFP_KERNEL); > > @@ -1611,8 +1613,10 @@ svcauth_gss_wrap_resp_integ(struct svc_rqst *rqstp) > > BUG_ON(integ_len % 4); > > *p++ = htonl(integ_len); > > *p++ = htonl(gc->gc_seq); > > - if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) > > - BUG(); > > + if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset, integ_len)) { > > + WARN_ON_ONCE(1); > > + goto out_err; > > + } > > if (resbuf->tail[0].iov_base == NULL) { > > if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE) > > goto out_err; > > What about the following BUG() at net/sunrpc/svc_xprt.c:1058: > > /* > * Remove a dead transport > */ > static void svc_delete_xprt(struct svc_xprt *xprt) > { > struct svc_serv *serv = xprt->xpt_server; > struct svc_deferred_req *dr; > > /* Only do this once */ > if (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) > BUG(); > > dprintk("svc: svc_delete_xprt(%p)\n", xprt); > xprt->xpt_ops->xpo_detach(xprt); > > spin_lock_bh(&serv->sv_lock); > list_del_init(&xprt->xpt_list); > WARN_ON_ONCE(!list_empty(&xprt->xpt_ready)); > if (test_bit(XPT_TEMP, &xprt->xpt_flags)) > serv->sv_tmpcnt--; > spin_unlock_bh(&serv->sv_lock); > > while ((dr = svc_deferred_dequeue(xprt)) != NULL) > kfree(dr); > > call_xpt_users(xprt); > svc_xprt_put(xprt); > } > > I'm suspicious about that comment above the _if_ condition: /* Only do > this once */ > > Would it help to replace that BUG with a WARN_ON_ONCE? > Maybe. How safe is it to run all of that more than once after XPT_DEAD is set? You'd probably just end up crashing at some later point down the line anyway... I suppose you could do a WARN() there and then return without actually doing anything. That might let you limp along if you did hit this. -- Jeff Layton <jlayton@redhat.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-10-25 17:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-23 18:16 [PATCH] net: sunrpc: svcauth_gss: use BUG_ON instead of if condition followed by BUG Gustavo A. R. Silva
[not found] ` <20171023181635.GA25334-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org>
2017-10-23 20:31 ` J. Bruce Fields
2017-10-24 17:26 ` Weston Andros Adamson
[not found] ` <496D700A-E9D1-4745-B5DE-24BB9231A449-J6AcJDG0ZEwdnm+yROfE0A@public.gmane.org>
2017-10-24 17:53 ` J. Bruce Fields
2017-10-24 18:18 ` Jeff Layton
2017-10-24 19:07 ` J. Bruce Fields
2017-10-24 20:12 ` Gustavo A. R. Silva
2017-10-25 17:04 ` Jeff Layton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).