Whamcloud - gitweb
LU-8260 osd-ldiskfs: osd_fiemap_get() fix address space mismatch 78/33878/6
authorArshad Hussain <arshad.super@gmail.com>
Tue, 4 Dec 2018 18:20:59 +0000 (23:50 +0530)
committerOleg Drokin <green@whamcloud.com>
Thu, 21 Mar 2019 03:42:29 +0000 (03:42 +0000)
There was an address space mismatch in function
osd_fiemap_get() as this uses "__user" qualifier
in fiemap_extent buffer. Since this buffer is created
under kernel and again passed to another call, this
may fail under some configuration.

This patch address this issue by modifying the
address space limit by using get_fs() and set_fs()
call suggesting that the pointers are intact and
secure.

Change-Id: I25048faecd3475d5e91e25e6a47e065e49e36b26
Signed-off-by: Arshad Hussain <arshad.super@gmail.com>
Reviewed-on: https://review.whamcloud.com/33878
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osd-ldiskfs/osd_io.c

index 59c87fc..7140abe 100644 (file)
@@ -2234,7 +2234,7 @@ static int osd_fiemap_get(const struct lu_env *env, struct dt_object *dt,
        struct inode *inode = osd_dt_obj(dt)->oo_inode;
        u64 len;
        int rc;
-
+       mm_segment_t cur_fs;
 
        LASSERT(inode);
        if (inode->i_op->fiemap == NULL)
@@ -2254,10 +2254,18 @@ static int osd_fiemap_get(const struct lu_env *env, struct dt_object *dt,
        if (fieinfo.fi_flags & FIEMAP_FLAG_SYNC)
                filemap_write_and_wait(inode->i_mapping);
 
+       /* Save previous value address limit */
+       cur_fs = get_fs();
+       /* Set the address limit of the kernel */
+       set_fs(get_ds());
+
        rc = inode->i_op->fiemap(inode, &fieinfo, fm->fm_start, len);
        fm->fm_flags = fieinfo.fi_flags;
        fm->fm_mapped_extents = fieinfo.fi_extents_mapped;
 
+       /* Restore the previous address limt */
+       set_fs(cur_fs);
+
        return rc;
 }