lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEKGpzj3AyU2cn4MTL_W2u2oFJEnC4MJLWx7WvdsvckzC2kOnQ@mail.gmail.com>
Date:   Sat, 5 Oct 2019 00:11:49 +0900
From:   "Daniel T. Lee" <danieltimlee@...il.com>
To:     Jesper Dangaard Brouer <brouer@...hat.com>
Cc:     Toke Høiland-Jørgensen <toke@...hat.com>,
        "David S . Miller" <davem@...emloft.net>,
        netdev <netdev@...r.kernel.org>
Subject: Re: [v4 2/4] samples: pktgen: fix proc_cmd command result check logic

On Fri, Oct 4, 2019 at 10:24 PM Jesper Dangaard Brouer
<brouer@...hat.com> wrote:
>
> [...]
>
> Is this comment still relevant?  You just excluded "pgctrl" from
> getting into this section.
>

Oops, will fix it right away.

> > +        if [[ "$result" == "" ]]; then
> > +        grep "Result:" $proc_ctrl >&2
>
> Missing tap/indention?
>
> > +        fi
> >      fi
> >      if (( $status != 0 )); then
> >       err 5 "Write error($status) occurred cmd: \"$@ > $proc_ctrl\""
> > @@ -105,6 +109,8 @@ function pgset() {
> >      fi
> >  }
> >
> > +trap 'pg_ctrl "reset"' EXIT
> > +
>
> This line is activated when I ctrl-C the scripts, but something weird
> happens, it reports:
>
>  ERROR: proc file:/proc/net/pktgen/pgctrl not writable, not root?!
>

Seems, the error is shown when the script is executed without sudo.
By grep-ing the debug info with 'set -x', you can find out that script elevate
itself to sudo by 'root_check_run_with_sudo'.

As you can see, there are three 'pg_ctrl reset'.

First one is called as preparation for packet sending,
Second is called as trap EXIT when sudo elevated script is done and exit.
Last one is also called as trap EXIT, but it is not executed as sudo.



$ ./pktgen_sample01_simple.sh 1>/dev/null 2>out
$ cat out | egrep -A 2 -B 2 'trap|sudo|pg_ctrl reset'
...
++ trap 'pg_ctrl "reset"' EXIT
+ root_check_run_with_sudo
+ '[' 1000 -ne 0 ']'
+ '[' -x ./pktgen_sample01_simple.sh ']'
+ info 'Not root, running with sudo'
+ [[ -n '' ]]
+ sudo ./pktgen_sample01_simple.sh
++ export PROC_DIR=/proc/net/pktgen
++ PROC_DIR=/proc/net/pktgen
++ trap 'pg_ctrl "reset"' EXIT
+ root_check_run_with_sudo
+ '[' 0 -ne 0 ']'
+ source ./parameters.sh
--
+ UDP_SRC_MIN=9
+ UDP_SRC_MAX=109
+ pg_ctrl reset
+ local proc_file=pgctrl
+ proc_cmd pgctrl reset
--
+ echo 'Result device: wlp2s0'
+ cat /proc/net/pktgen/wlp2s0
+ pg_ctrl reset
+ local proc_file=pgctrl
+ proc_cmd pgctrl reset
--
+ ((  0 != 0  ))
+ exit 0
+ pg_ctrl reset
+ local proc_file=pgctrl
+ proc_cmd pgctrl reset


As for solution, only call 'pg_ctrl reset' when it's running as sudo
will solve the problem.
-trap 'pg_ctrl "reset"' EXIT
+trap '[[ $EUID -eq 0 ]] && pg_ctrl "reset"' EXIT

Will apply this at next version of patch.

Thanks,
Daniel

>
> >  ## -- General shell tricks --
> >
> >  function root_check_run_with_sudo() {
>
>
>
> --
> Best regards,
>   Jesper Dangaard Brouer
>   MSc.CS, Principal Kernel Engineer at Red Hat
>   LinkedIn: http://www.linkedin.com/in/brouer

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ