From b6d08e58079ac7e8f3083fde22cbb484a16bbc12 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 13 Jan 2019 19:43:31 +0000 Subject: [PATCH] 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 --- scst/src/scst_lib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 6d9d184af..0aeed0ae8 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -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)