diff options
author | Jeff Layton <jlayton@kernel.org> | 2019-06-24 13:32:21 +0200 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2019-07-08 14:01:44 +0200 |
commit | 26350535c2cef4bcf5de597c301b0560650cec19 (patch) | |
tree | 9d9de3607ab7c81465612a3106f04120e8d8c31a /drivers/block/rbd.c | |
parent | ceph: return -ERANGE if virtual xattr value didn't fit in buffer (diff) | |
download | linux-26350535c2cef4bcf5de597c301b0560650cec19.tar.xz linux-26350535c2cef4bcf5de597c301b0560650cec19.zip |
ceph: don't NULL terminate virtual xattrs
The convention with xattrs is to not store the termination with string
data, given that it returns the length. This is how setfattr/getfattr
operate.
Most of ceph's virtual xattr routines use snprintf to plop the string
directly into the destination buffer, but snprintf always NULL
terminates the string. This means that if we send the kernel a buffer
that is the exact length needed to hold the string, it'll end up
truncated.
Add a ceph_fmt_xattr helper function to format the string into an
on-stack buffer that should always be large enough to hold the whole
thing and then memcpy the result into the destination buffer. If it does
turn out that the formatted string won't fit in the on-stack buffer,
then return -E2BIG and do a WARN_ONCE().
Change over most of the virtual xattr routines to use the new helper. A
couple of the xattrs are sourced from strings however, and it's
difficult to know how long they'll be. Just have those memcpy the result
in place after verifying the length.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Acked-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'drivers/block/rbd.c')
0 files changed, 0 insertions, 0 deletions