scst: Complain loudly if 'fs' is incorrect

Since not setting the fs register correctly leads to silent data
corruption, if scst_read(), scst_write(), scst_readv() or scst_writev()
is called, complain loudly if 'fs' has not been set correctly.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7873 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2019-01-13 19:43:31 +00:00
parent 4515746ea2
commit b6d08e5807

View File

@@ -5946,6 +5946,14 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd)
return;
}
static int scst_cmp_fs_ds(void)
{
mm_segment_t fs = get_fs();
mm_segment_t ds = get_ds();
return memcmp(&fs, &ds, sizeof(fs));
}
ssize_t scst_read(struct file *file, void *buf, size_t count, loff_t *pos)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
@@ -5954,6 +5962,8 @@ ssize_t scst_read(struct file *file, void *buf, size_t count, loff_t *pos)
.iov_len = count
};
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
return scst_readv(file, &iov, 1, pos);
#else
return vfs_read(file, (void __force __user *)buf, count, pos);
@@ -5970,6 +5980,8 @@ ssize_t scst_write(struct file *file, const void *buf, size_t count,
.iov_len = count
};
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
return scst_writev(file, &iov, 1, pos);
#else
return vfs_write(file, (void __force __user *)buf, count, pos);
@@ -5986,6 +5998,8 @@ ssize_t scst_readv(struct file *file, const struct iovec *vec,
struct iov_iter iter;
ssize_t ret;
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
ret = import_iovec(READ, (const struct iovec __force __user *)vec, vlen,
ARRAY_SIZE(iovstack), &iov, &iter);
if (ret < 0)
@@ -6023,6 +6037,8 @@ ssize_t scst_writev(struct file *file, const struct iovec *vec,
struct iov_iter iter;
ssize_t ret;
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
ret = import_iovec(WRITE, (const struct iovec __force __user *)vec,
vlen, ARRAY_SIZE(iovstack), &iov, &iter);
if (ret < 0)