linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chengguang Xu <cgxu519@mykernel.net>
To: viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, Chengguang Xu <cgxu519@mykernel.net>
Subject: [PATCH] vfs/xattr: strengthen error check to avoid unexpected result
Date: Wed, 17 Jun 2020 09:08:27 +0800	[thread overview]
Message-ID: <20200617010827.16048-1-cgxu519@mykernel.net> (raw)

The variable error is ssize_t, which is signed and will
cast to unsigned when comapre with variable size, so add
a check to avoid unexpected result in case of negative
value of error.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index e13265e65871..9d0f12682c86 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -356,7 +356,7 @@ vfs_listxattr(struct dentry *dentry, char *list, size_t size)
 		error = inode->i_op->listxattr(dentry, list, size);
 	} else {
 		error = security_inode_listsecurity(inode, list, size);
-		if (size && error > size)
+		if (error >= 0 && size && error > size)
 			error = -ERANGE;
 	}
 	return error;
-- 
2.20.1



                 reply	other threads:[~2020-06-17  1:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200617010827.16048-1-cgxu519@mykernel.net \
    --to=cgxu519@mykernel.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).