* [PATCH] ext4: avoid unneeded lookup when xattr name is invalid
[not found] <1397199813-71623-1-git-send-email-zhenzhang.zhang@huawei.com>
@ 2014-04-11 7:15 ` Zhang Zhen
2014-05-12 14:00 ` Theodore Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Zhang Zhen @ 2014-04-11 7:15 UTC (permalink / raw)
To: tytso, Christoph Hellwig; +Cc: linux-ext4
In ext4_xattr_set_handle() we have checked the xattr name's length. So we should
also check it in ext4_xattr_get() to avoid unneeded lookup caused by invalid name.
In addition, we deleted the check of NULL in ext4_xattr_set_handle(), because in all
the callers of the ext4_xattr_set_handle(), the name can't be NULL.
Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
---
fs/ext4/xattr.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 1f5cf58..340bdfa 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -369,6 +369,9 @@ ext4_xattr_get(struct inode *inode, int name_index, const char *name,
{
int error;
+ if (strlen(name) > 255)
+ return -ERANGE;
+
down_read(&EXT4_I(inode)->xattr_sem);
error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
buffer_size);
@@ -1073,8 +1076,6 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
unsigned long no_expand;
int error;
- if (!name)
- return -EINVAL;
if (strlen(name) > 255)
return -ERANGE;
down_write(&EXT4_I(inode)->xattr_sem);
--
1.8.5.5
.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4: avoid unneeded lookup when xattr name is invalid
2014-04-11 7:15 ` [PATCH] ext4: avoid unneeded lookup when xattr name is invalid Zhang Zhen
@ 2014-05-12 14:00 ` Theodore Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2014-05-12 14:00 UTC (permalink / raw)
To: Zhang Zhen; +Cc: Christoph Hellwig, linux-ext4
On Fri, Apr 11, 2014 at 03:15:07PM +0800, Zhang Zhen wrote:
> In ext4_xattr_set_handle() we have checked the xattr name's length. So we should
> also check it in ext4_xattr_get() to avoid unneeded lookup caused by invalid name.
>
> Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
Applied, although I dropped this bit:
> In addition, we deleted the check of NULL in ext4_xattr_set_handle(), because in all
> the callers of the ext4_xattr_set_handle(), the name can't be NULL.
Verifying this is non-trivial, since there are many non-local
users of this function, and in order to make sure this is true you
need to verify (at least) the callers of the callers. I could be
convinced to turn this into a BUG_ON(!name), or "if
(unlikely(!name))", but leaving the check in is a good idea, since
even if it is true today, it's not necessarily guarantted to be true N
years in the future.
- Ted
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-12 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1397199813-71623-1-git-send-email-zhenzhang.zhang@huawei.com>
2014-04-11 7:15 ` [PATCH] ext4: avoid unneeded lookup when xattr name is invalid Zhang Zhen
2014-05-12 14:00 ` Theodore Ts'o
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).