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: <CAK7LNATOzfM_5ntS9TiT1=04u28tBvmPJsUWyTptZkS630B-oQ@mail.gmail.com>
Date:   Mon, 23 Jan 2023 02:59:05 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     Kees Cook <keescook@...omium.org>
Cc:     linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org,
        Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Tom Rix <trix@...hat.com>, llvm@...ts.linux.dev
Subject: Re: [PATCH] scripts: handle BrokenPipeError for python scripts

On Sun, Jan 15, 2023 at 12:04 PM Masahiro Yamada <masahiroy@...nel.org> wrote:
>
> On Fri, Jan 13, 2023 at 7:06 AM Kees Cook <keescook@...omium.org> wrote:
> >
> > On Thu, Jan 12, 2023 at 11:30:06AM +0900, Masahiro Yamada wrote:
> > >     def main():
> > >         try:
> > >             # simulate large output (your code replaces this loop)
> > >             for x in range(10000):
> > >                 print("y")
> > >             # flush output here to force SIGPIPE to be triggered
> > >             # while inside this try block.
> > >             sys.stdout.flush()
> > >         except BrokenPipeError:
> > >             # Python flushes standard streams on exit; redirect remaining output
> > >             # to devnull to avoid another BrokenPipeError at shutdown
> > >             devnull = os.open(os.devnull, os.O_WRONLY)
> > >             os.dup2(devnull, sys.stdout.fileno())
> > >             sys.exit(1)  # Python exits with error code 1 on EPIPE
> >
> > I still think this is wrong -- they should not continue piping, and
> > should just die with SIGPIPE. It should simply be:
> >
> > signal(SIGPIPE, SIG_DFL);
> >
> > Nothing else needed. No wasted CPU cycles, shell handling continues as
> > per normal.
>
>
> I prefer try-and-except because it is Python's coding style,
> and we can do something before the exit.
> (for example, clean up temporary files)
>
>
> >
> > >     if __name__ == '__main__':
> > >         main()
> > >
> > >   Do not set SIGPIPE’s disposition to SIG_DFL in order to avoid
> > >   BrokenPipeError. Doing that would cause your program to exit
> > >   unexpectedly whenever any socket connection is interrupted while
> > >   your program is still writing to it.
> >
> > This advise is for socket programs, not command-line tools.
>
>
> I still do not understand what is bad
> about using this for command-line tools.
>
>
> >
> > -Kees
> >
> > --
> > Kees Cook
>
>
>
> --
> Best Regards
> Masahiro Yamada




Applied with the typos fixes.




-- 
Best Regards
Masahiro Yamada

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ