From: Nikolay Borisov <nborisov@suse.com>
To: eguan@redhat.com
Cc: fstests@vger.kernel.org
Subject: Re: [PATCHv2] src/listxattr: Fix reading past the end of the user buffer
Date: Wed, 31 May 2017 11:58:12 +0300 [thread overview]
Message-ID: <70269450-8b2e-3b8f-e7ac-e44221797e34@suse.com> (raw)
In-Reply-To: <1496153407-6060-1-git-send-email-nborisov@suse.com>
On 30.05.2017 17:10, Nikolay Borisov wrote:
> listxattr reaturns a null-terminated list of entries that represent
> the xattr names. However, if it is passed larger buffer than it
> requires it won't zero-out the rest of the memory. The way the
> loop iterator in listxattr.c is written makes it go print every
> null-terminated entry up to bufsize (which is user passed parameter).
> This can lead to a situation where listxattr users N bytes out of
> M bytes big buffer ( M > N). This will leave the rest (M-N)
> as garbage, which in turn will be printed by listxattr. Fix this
> by converting the 'for' loop to 'while' and properly ensuring
> we are reading at most howevermany elements the syscall reported
> it returned
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>
> v2:
> Rewrite the loop, hopefully making the code a bit more legible.
> Functionally it's the same as my previous fix
>
> src/listxattr.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/listxattr.c b/src/listxattr.c
> index cd46637a..584ebb2d 100644
> --- a/src/listxattr.c
> +++ b/src/listxattr.c
> @@ -60,10 +60,10 @@ int main(int argc, char **argv)
> if (ret < 0) {
> perror("listxattr");
> } else {
> - char *l;
> - for (l = buf; l != (buf + bufsize) && *l != '\0';
> - l = strchr(l, '\0') + 1) {
> + char *l = buf;
> + while (l != (buf + ret)) {
Actually I believe while (l < (buf + ret)) is the correct form.
> printf("xattr: %s\n", l);
> + l = strchr(l, '\0') + 1;
> }
> }
>
>
next prev parent reply other threads:[~2017-05-31 8:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-30 13:51 [PATCH] listxattr: Fix read past end of array Nikolay Borisov
2017-05-30 14:10 ` [PATCHv2] src/listxattr: Fix reading past the end of the user buffer Nikolay Borisov
2017-05-31 8:58 ` Nikolay Borisov [this message]
2017-06-01 5:04 ` Eryu Guan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=70269450-8b2e-3b8f-e7ac-e44221797e34@suse.com \
--to=nborisov@suse.com \
--cc=eguan@redhat.com \
--cc=fstests@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox