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] [thread-next>] [day] [month] [year] [list]
Message-ID: <bf57f48d5318450b95746f9f91418153@AcuMS.aculab.com>
Date:   Tue, 21 May 2019 15:05:31 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Chang-Hsien Tsai' <luke.tw@...il.com>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC:     "ast@...nel.org" <ast@...nel.org>,
        "daniel@...earbox.net" <daniel@...earbox.net>,
        "kafai@...com" <kafai@...com>,
        "songliubraving@...com" <songliubraving@...com>,
        "yhs@...com" <yhs@...com>
Subject: RE: [PATCH] samples: bpf: fix: change the buffer size for read()

From: Chang-Hsien Tsai
> Sent: 19 May 2019 10:06
> If the trace for read is larger than 4096,
> the return value sz will be 4096.
> This results in off-by-one error on buf.
> 
>     static char buf[4096];
>     ssize_t sz;
> 
>     sz = read(trace_fd, buf, sizeof(buf));
>     if (sz > 0) {
>         buf[sz] = 0;
>         puts(buf);
>     }
> 
> Signed-off-by: Chang-Hsien Tsai <luke.tw@...il.com>
> ---
>  samples/bpf/bpf_load.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
> index eae7b635343d..d4da90070b58 100644
> --- a/samples/bpf/bpf_load.c
> +++ b/samples/bpf/bpf_load.c
> @@ -678,7 +678,7 @@ void read_trace_pipe(void)
>  		static char buf[4096];
>  		ssize_t sz;
> 
> -		sz = read(trace_fd, buf, sizeof(buf));
> +		sz = read(trace_fd, buf, sizeof(buf)-1);
>  		if (sz > 0) {
>  			buf[sz] = 0;
>  			puts(buf);

Why not change the puts() to fwrite(buf, sz, 1, stdout) ?
Then you don't need the '\0' terminator.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ