diff mbox series

[v3,5/7] drm/i915: Check if the size is too big while creating shmem file

Message ID 20220714090807.2340818-6-gwan-gyeong.mun@intel.com (mailing list archive)
State New, archived
Headers show
Series Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation | expand

Commit Message

Gwan-gyeong Mun July 14, 2022, 9:08 a.m. UTC
The __shmem_file_setup() function returns -EINVAL if size is greater than
MAX_LFS_FILESIZE. To handle the same error as other code that returns
-E2BIG when the size is too large, it add a code that returns -E2BIG when
the size is larger than the size that can be handled.

Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

kernel test robot July 16, 2022, 3:01 a.m. UTC | #1
Hi Gwan-gyeong,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]

url:    https://github.com/intel-lab-lkp/linux/commits/Gwan-gyeong-Mun/Fixes-integer-overflow-or-integer-truncation-issues-in-page-lookups-ttm-place-configuration-and-scatterlist-creation/20220714-171019
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: i386-randconfig-a013
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 2da550140aa98cf6a3e96417c87f1e89e3a26047)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/2938379499047baf3189503913f438fda6ea92eb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Gwan-gyeong-Mun/Fixes-integer-overflow-or-integer-truncation-issues-in-page-lookups-ttm-place-configuration-and-scatterlist-creation/20220714-171019
        git checkout 2938379499047baf3189503913f438fda6ea92eb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/i915/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/gem/i915_gem_shmem.c:550:11: warning: result of comparison of constant 17592186040320 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
           if (size > MAX_LFS_FILESIZE)
               ~~~~ ^ ~~~~~~~~~~~~~~~~
   1 warning generated.


vim +550 drivers/gpu/drm/i915/gem/i915_gem_shmem.c

   534	
   535	static int __create_shmem(struct drm_i915_private *i915,
   536				  struct drm_gem_object *obj,
   537				  resource_size_t size)
   538	{
   539		unsigned long flags = VM_NORESERVE;
   540		struct file *filp;
   541	
   542		drm_gem_private_object_init(&i915->drm, obj, size);
   543	
   544		/* XXX: The __shmem_file_setup() function returns -EINVAL if size is
   545		 * greater than MAX_LFS_FILESIZE.
   546		 * To handle the same error as other code that returns -E2BIG when
   547		 * the size is too large, we add a code that returns -E2BIG when the
   548		 * size is larger than the size that can be handled.
   549		 */
 > 550		if (size > MAX_LFS_FILESIZE)
   551			return -E2BIG;
   552	
   553		if (i915->mm.gemfs)
   554			filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size,
   555							 flags);
   556		else
   557			filp = shmem_file_setup("i915", size, flags);
   558		if (IS_ERR(filp))
   559			return PTR_ERR(filp);
   560	
   561		obj->filp = filp;
   562		return 0;
   563	}
   564
kernel test robot July 16, 2022, 3:12 a.m. UTC | #2
Hi Gwan-gyeong,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]

url:    https://github.com/intel-lab-lkp/linux/commits/Gwan-gyeong-Mun/Fixes-integer-overflow-or-integer-truncation-issues-in-page-lookups-ttm-place-configuration-and-scatterlist-creation/20220714-171019
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: i386-randconfig-a004 (https://download.01.org/0day-ci/archive/20220716/202207161058.dmOZoQzg-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 2da550140aa98cf6a3e96417c87f1e89e3a26047)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/2938379499047baf3189503913f438fda6ea92eb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Gwan-gyeong-Mun/Fixes-integer-overflow-or-integer-truncation-issues-in-page-lookups-ttm-place-configuration-and-scatterlist-creation/20220714-171019
        git checkout 2938379499047baf3189503913f438fda6ea92eb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/i915/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/gem/i915_gem_shmem.c:550:11: warning: result of comparison of constant 17592186040320 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
           if (size > MAX_LFS_FILESIZE)
               ~~~~ ^ ~~~~~~~~~~~~~~~~
   1 warning generated.


vim +550 drivers/gpu/drm/i915/gem/i915_gem_shmem.c

   534	
   535	static int __create_shmem(struct drm_i915_private *i915,
   536				  struct drm_gem_object *obj,
   537				  resource_size_t size)
   538	{
   539		unsigned long flags = VM_NORESERVE;
   540		struct file *filp;
   541	
   542		drm_gem_private_object_init(&i915->drm, obj, size);
   543	
   544		/* XXX: The __shmem_file_setup() function returns -EINVAL if size is
   545		 * greater than MAX_LFS_FILESIZE.
   546		 * To handle the same error as other code that returns -E2BIG when
   547		 * the size is too large, we add a code that returns -E2BIG when the
   548		 * size is larger than the size that can be handled.
   549		 */
 > 550		if (size > MAX_LFS_FILESIZE)
   551			return -E2BIG;
   552	
   553		if (i915->mm.gemfs)
   554			filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size,
   555							 flags);
   556		else
   557			filp = shmem_file_setup("i915", size, flags);
   558		if (IS_ERR(filp))
   559			return PTR_ERR(filp);
   560	
   561		obj->filp = filp;
   562		return 0;
   563	}
   564
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
index 604e8829e8ea..8495e87432f6 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
@@ -541,6 +541,15 @@  static int __create_shmem(struct drm_i915_private *i915,
 
 	drm_gem_private_object_init(&i915->drm, obj, size);
 
+	/* XXX: The __shmem_file_setup() function returns -EINVAL if size is
+	 * greater than MAX_LFS_FILESIZE.
+	 * To handle the same error as other code that returns -E2BIG when
+	 * the size is too large, we add a code that returns -E2BIG when the
+	 * size is larger than the size that can be handled.
+	 */
+	if (size > MAX_LFS_FILESIZE)
+		return -E2BIG;
+
 	if (i915->mm.gemfs)
 		filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size,
 						 flags);