2021-11-18 00:11:07 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
/* CacheFiles extended attribute management
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/fsnotify.h>
|
|
|
|
#include <linux/quotaops.h>
|
|
|
|
#include <linux/xattr.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
#define CACHEFILES_COOKIE_TYPE_DATA 1
|
|
|
|
|
|
|
|
struct cachefiles_xattr {
|
|
|
|
__be64 object_size; /* Actual size of the object */
|
|
|
|
__be64 zero_point; /* Size after which server has no data not written by us */
|
|
|
|
__u8 type; /* Type of object */
|
|
|
|
__u8 content; /* Content presence (enum cachefiles_content) */
|
|
|
|
__u8 data[]; /* netfs coherency data */
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
static const char cachefiles_xattr_cache[] =
|
|
|
|
XATTR_USER_PREFIX "CacheFiles.cache";
|
|
|
|
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
struct cachefiles_vol_xattr {
|
|
|
|
__be32 reserved; /* Reserved, should be 0 */
|
|
|
|
__u8 data[]; /* netfs volume coherency data */
|
|
|
|
} __packed;
|
|
|
|
|
2021-11-18 00:11:07 +08:00
|
|
|
/*
|
|
|
|
* set the state xattr on a cache file
|
|
|
|
*/
|
|
|
|
int cachefiles_set_object_xattr(struct cachefiles_object *object)
|
|
|
|
{
|
|
|
|
struct cachefiles_xattr *buf;
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct file *file = object->file;
|
|
|
|
unsigned int len = object->cookie->aux_len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return -ESTALE;
|
|
|
|
dentry = file->f_path.dentry;
|
|
|
|
|
|
|
|
_enter("%x,#%d", object->debug_id, len);
|
|
|
|
|
|
|
|
buf = kmalloc(sizeof(struct cachefiles_xattr) + len, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
buf->object_size = cpu_to_be64(object->cookie->object_size);
|
|
|
|
buf->zero_point = 0;
|
|
|
|
buf->type = CACHEFILES_COOKIE_TYPE_DATA;
|
|
|
|
buf->content = object->content_info;
|
|
|
|
if (test_bit(FSCACHE_COOKIE_LOCAL_WRITE, &object->cookie->flags))
|
|
|
|
buf->content = CACHEFILES_CONTENT_DIRTY;
|
|
|
|
if (len > 0)
|
|
|
|
memcpy(buf->data, fscache_get_aux(object->cookie), len);
|
|
|
|
|
|
|
|
ret = cachefiles_inject_write_error();
|
|
|
|
if (ret == 0)
|
2023-01-13 19:49:22 +08:00
|
|
|
ret = vfs_setxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache,
|
2021-11-18 00:11:07 +08:00
|
|
|
buf, sizeof(struct cachefiles_xattr) + len, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
trace_cachefiles_vfs_error(object, file_inode(file), ret,
|
|
|
|
cachefiles_trace_setxattr_error);
|
|
|
|
trace_cachefiles_coherency(object, file_inode(file)->i_ino,
|
|
|
|
buf->content,
|
|
|
|
cachefiles_coherency_set_fail);
|
|
|
|
if (ret != -ENOMEM)
|
|
|
|
cachefiles_io_error_obj(
|
|
|
|
object,
|
|
|
|
"Failed to set xattr with error %d", ret);
|
|
|
|
} else {
|
|
|
|
trace_cachefiles_coherency(object, file_inode(file)->i_ino,
|
|
|
|
buf->content,
|
|
|
|
cachefiles_coherency_set_ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the consistency between the backing cache and the FS-Cache cookie
|
|
|
|
*/
|
|
|
|
int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file)
|
|
|
|
{
|
|
|
|
struct cachefiles_xattr *buf;
|
|
|
|
struct dentry *dentry = file->f_path.dentry;
|
|
|
|
unsigned int len = object->cookie->aux_len, tlen;
|
|
|
|
const void *p = fscache_get_aux(object->cookie);
|
|
|
|
enum cachefiles_coherency_trace why;
|
|
|
|
ssize_t xlen;
|
|
|
|
int ret = -ESTALE;
|
|
|
|
|
|
|
|
tlen = sizeof(struct cachefiles_xattr) + len;
|
|
|
|
buf = kmalloc(tlen, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
xlen = cachefiles_inject_read_error();
|
|
|
|
if (xlen == 0)
|
2023-01-13 19:49:22 +08:00
|
|
|
xlen = vfs_getxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, buf, tlen);
|
2021-11-18 00:11:07 +08:00
|
|
|
if (xlen != tlen) {
|
|
|
|
if (xlen < 0)
|
|
|
|
trace_cachefiles_vfs_error(object, file_inode(file), xlen,
|
|
|
|
cachefiles_trace_getxattr_error);
|
|
|
|
if (xlen == -EIO)
|
|
|
|
cachefiles_io_error_obj(
|
|
|
|
object,
|
|
|
|
"Failed to read aux with error %zd", xlen);
|
|
|
|
why = cachefiles_coherency_check_xattr;
|
|
|
|
} else if (buf->type != CACHEFILES_COOKIE_TYPE_DATA) {
|
|
|
|
why = cachefiles_coherency_check_type;
|
|
|
|
} else if (memcmp(buf->data, p, len) != 0) {
|
|
|
|
why = cachefiles_coherency_check_aux;
|
|
|
|
} else if (be64_to_cpu(buf->object_size) != object->cookie->object_size) {
|
|
|
|
why = cachefiles_coherency_check_objsize;
|
|
|
|
} else if (buf->content == CACHEFILES_CONTENT_DIRTY) {
|
|
|
|
// TODO: Begin conflict resolution
|
|
|
|
pr_warn("Dirty object in cache\n");
|
|
|
|
why = cachefiles_coherency_check_dirty;
|
|
|
|
} else {
|
|
|
|
why = cachefiles_coherency_check_ok;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_cachefiles_coherency(object, file_inode(file)->i_ino,
|
|
|
|
buf->content, why);
|
|
|
|
kfree(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove the object's xattr to mark it stale
|
|
|
|
*/
|
|
|
|
int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
|
|
|
|
struct cachefiles_object *object,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = cachefiles_inject_remove_error();
|
|
|
|
if (ret == 0)
|
2023-01-13 19:49:22 +08:00
|
|
|
ret = vfs_removexattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache);
|
2021-11-18 00:11:07 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
trace_cachefiles_vfs_error(object, d_inode(dentry), ret,
|
|
|
|
cachefiles_trace_remxattr_error);
|
|
|
|
if (ret == -ENOENT || ret == -ENODATA)
|
|
|
|
ret = 0;
|
|
|
|
else if (ret != -ENOMEM)
|
|
|
|
cachefiles_io_error(cache,
|
|
|
|
"Can't remove xattr from %lu"
|
|
|
|
" (error %d)",
|
|
|
|
d_backing_inode(dentry)->i_ino, -ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stick a marker on the cache object to indicate that it's dirty.
|
|
|
|
*/
|
|
|
|
void cachefiles_prepare_to_write(struct fscache_cookie *cookie)
|
|
|
|
{
|
|
|
|
const struct cred *saved_cred;
|
|
|
|
struct cachefiles_object *object = cookie->cache_priv;
|
|
|
|
struct cachefiles_cache *cache = object->volume->cache;
|
|
|
|
|
|
|
|
_enter("c=%08x", object->cookie->debug_id);
|
|
|
|
|
|
|
|
if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) {
|
|
|
|
cachefiles_begin_secure(cache, &saved_cred);
|
|
|
|
cachefiles_set_object_xattr(object);
|
|
|
|
cachefiles_end_secure(cache, saved_cred);
|
|
|
|
}
|
|
|
|
}
|
2021-12-14 17:51:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the state xattr on a volume directory.
|
|
|
|
*/
|
|
|
|
bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
|
|
|
|
{
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
struct cachefiles_vol_xattr *buf;
|
2021-12-14 17:51:43 +08:00
|
|
|
unsigned int len = volume->vcookie->coherency_len;
|
|
|
|
const void *p = volume->vcookie->coherency;
|
|
|
|
struct dentry *dentry = volume->dentry;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
_enter("%x,#%d", volume->vcookie->debug_id, len);
|
|
|
|
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
len += sizeof(*buf);
|
|
|
|
buf = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return false;
|
|
|
|
buf->reserved = cpu_to_be32(0);
|
2022-04-05 21:46:49 +08:00
|
|
|
memcpy(buf->data, p, volume->vcookie->coherency_len);
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
|
2021-12-14 17:51:43 +08:00
|
|
|
ret = cachefiles_inject_write_error();
|
|
|
|
if (ret == 0)
|
2023-01-13 19:49:22 +08:00
|
|
|
ret = vfs_setxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache,
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
buf, len, 0);
|
2021-12-14 17:51:43 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
trace_cachefiles_vfs_error(NULL, d_inode(dentry), ret,
|
|
|
|
cachefiles_trace_setxattr_error);
|
|
|
|
trace_cachefiles_vol_coherency(volume, d_inode(dentry)->i_ino,
|
|
|
|
cachefiles_coherency_vol_set_fail);
|
|
|
|
if (ret != -ENOMEM)
|
|
|
|
cachefiles_io_error(
|
|
|
|
volume->cache, "Failed to set xattr with error %d", ret);
|
|
|
|
} else {
|
|
|
|
trace_cachefiles_vol_coherency(volume, d_inode(dentry)->i_ino,
|
|
|
|
cachefiles_coherency_vol_set_ok);
|
|
|
|
}
|
|
|
|
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
kfree(buf);
|
2021-12-14 17:51:43 +08:00
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the consistency between the backing cache and the volume cookie.
|
|
|
|
*/
|
|
|
|
int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)
|
|
|
|
{
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
struct cachefiles_vol_xattr *buf;
|
2021-12-14 17:51:43 +08:00
|
|
|
struct dentry *dentry = volume->dentry;
|
|
|
|
unsigned int len = volume->vcookie->coherency_len;
|
|
|
|
const void *p = volume->vcookie->coherency;
|
|
|
|
enum cachefiles_coherency_trace why;
|
|
|
|
ssize_t xlen;
|
|
|
|
int ret = -ESTALE;
|
|
|
|
|
|
|
|
_enter("");
|
|
|
|
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
len += sizeof(*buf);
|
2021-12-14 17:51:43 +08:00
|
|
|
buf = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
xlen = cachefiles_inject_read_error();
|
|
|
|
if (xlen == 0)
|
2023-01-13 19:49:22 +08:00
|
|
|
xlen = vfs_getxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, buf, len);
|
2021-12-14 17:51:43 +08:00
|
|
|
if (xlen != len) {
|
|
|
|
if (xlen < 0) {
|
|
|
|
trace_cachefiles_vfs_error(NULL, d_inode(dentry), xlen,
|
|
|
|
cachefiles_trace_getxattr_error);
|
|
|
|
if (xlen == -EIO)
|
|
|
|
cachefiles_io_error(
|
|
|
|
volume->cache,
|
|
|
|
"Failed to read xattr with error %zd", xlen);
|
|
|
|
}
|
|
|
|
why = cachefiles_coherency_vol_check_xattr;
|
cachefiles: Fix volume coherency attribute
A network filesystem may set coherency data on a volume cookie, and if
given, cachefiles will store this in an xattr on the directory in the
cache corresponding to the volume.
The function that sets the xattr just stores the contents of the volume
coherency buffer directly into the xattr, with nothing added; the
checking function, on the other hand, has a cut'n'paste error whereby it
tries to interpret the xattr contents as would be the xattr on an
ordinary file (using the cachefiles_xattr struct). This results in a
failure to match the coherency data because the buffer ends up being
shifted by 18 bytes.
Fix this by defining a structure specifically for the volume xattr and
making both the setting and checking functions use it.
Since the volume coherency doesn't work if used, take the opportunity to
insert a reserved field for future use, set it to 0 and check that it is
0. Log mismatch through the appropriate tracepoint.
Note that this only affects cifs; 9p, afs, ceph and nfs don't use the
volume coherency data at the moment.
Fixes: 32e150037dce ("fscache, cachefiles: Store the volume coherency data")
Reported-by: Rohith Surabattula <rohiths.msft@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: Steve French <smfrench@gmail.com>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-03-12 00:02:18 +08:00
|
|
|
} else if (buf->reserved != cpu_to_be32(0)) {
|
|
|
|
why = cachefiles_coherency_vol_check_resv;
|
|
|
|
} else if (memcmp(buf->data, p, len - sizeof(*buf)) != 0) {
|
2021-12-14 17:51:43 +08:00
|
|
|
why = cachefiles_coherency_vol_check_cmp;
|
|
|
|
} else {
|
|
|
|
why = cachefiles_coherency_vol_check_ok;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_cachefiles_vol_coherency(volume, d_inode(dentry)->i_ino, why);
|
|
|
|
kfree(buf);
|
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|