diff mbox series

[ovs-dev] netdev-linux: Avoid division by 0 if kernel reports bad scheduler data.

Message ID 20180818171737.29772-1-blp@ovn.org
State Accepted
Headers show
Series [ovs-dev] netdev-linux: Avoid division by 0 if kernel reports bad scheduler data. | expand

Commit Message

Ben Pfaff Aug. 18, 2018, 5:17 p.m. UTC
If the kernel reported a value of 0 for the second value in
/proc/net/psched, it would cause a division-by-zero fault in
read_psched().  I don't know of a kernel that would actually do that, but
it's still better to be safe.

Found by clang static analyzer

Reported-by: Bhargava Shastry <bshastry@sect.tu-berlin.de>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/netdev-linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yifeng Sun Aug. 20, 2018, 4:15 p.m. UTC | #1
Looks good to me, thanks.

Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>

On Sat, Aug 18, 2018 at 10:17 AM, Ben Pfaff <blp@ovn.org> wrote:

> If the kernel reported a value of 0 for the second value in
> /proc/net/psched, it would cause a division-by-zero fault in
> read_psched().  I don't know of a kernel that would actually do that, but
> it's still better to be safe.
>
> Found by clang static analyzer
>
> Reported-by: Bhargava Shastry <bshastry@sect.tu-berlin.de>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---
>  lib/netdev-linux.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> index 0c42268d9d6c..e16ea58a085e 100644
> --- a/lib/netdev-linux.c
> +++ b/lib/netdev-linux.c
> @@ -5166,7 +5166,7 @@ read_psched(void)
>      VLOG_DBG("%s: psched parameters are: %u %u %u %u", fn, a, b, c, d);
>      fclose(stream);
>
> -    if (!a || !c) {
> +    if (!a || !b || !c) {
>          VLOG_WARN("%s: invalid scheduler parameters", fn);
>          goto exit;
>      }
> --
> 2.16.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Ben Pfaff Aug. 20, 2018, 4:31 p.m. UTC | #2
Thanks, applied to master and backported.

On Mon, Aug 20, 2018 at 09:15:54AM -0700, Yifeng Sun wrote:
> Looks good to me, thanks.
> 
> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
> 
> On Sat, Aug 18, 2018 at 10:17 AM, Ben Pfaff <blp@ovn.org> wrote:
> 
> > If the kernel reported a value of 0 for the second value in
> > /proc/net/psched, it would cause a division-by-zero fault in
> > read_psched().  I don't know of a kernel that would actually do that, but
> > it's still better to be safe.
> >
> > Found by clang static analyzer
> >
> > Reported-by: Bhargava Shastry <bshastry@sect.tu-berlin.de>
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > ---
> >  lib/netdev-linux.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> > index 0c42268d9d6c..e16ea58a085e 100644
> > --- a/lib/netdev-linux.c
> > +++ b/lib/netdev-linux.c
> > @@ -5166,7 +5166,7 @@ read_psched(void)
> >      VLOG_DBG("%s: psched parameters are: %u %u %u %u", fn, a, b, c, d);
> >      fclose(stream);
> >
> > -    if (!a || !c) {
> > +    if (!a || !b || !c) {
> >          VLOG_WARN("%s: invalid scheduler parameters", fn);
> >          goto exit;
> >      }
> > --
> > 2.16.1
> >
> > _______________________________________________
> > dev mailing list
> > dev@openvswitch.org
> > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
> >
diff mbox series

Patch

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 0c42268d9d6c..e16ea58a085e 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -5166,7 +5166,7 @@  read_psched(void)
     VLOG_DBG("%s: psched parameters are: %u %u %u %u", fn, a, b, c, d);
     fclose(stream);
 
-    if (!a || !c) {
+    if (!a || !b || !c) {
         VLOG_WARN("%s: invalid scheduler parameters", fn);
         goto exit;
     }