Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp222259rwb; Wed, 28 Sep 2022 01:35:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PtdzC8A7YkgPEgTP2VBVCye1C6CzfhRzTgLOwhPec2XKM5mrcxnY8mygAkE6hM03Ve8F8 X-Received: by 2002:a05:6a00:1a0e:b0:547:1cf9:40e8 with SMTP id g14-20020a056a001a0e00b005471cf940e8mr33539244pfv.82.1664354157939; Wed, 28 Sep 2022 01:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664354157; cv=none; d=google.com; s=arc-20160816; b=V9+EL7+tDqhjDJVkQKlcWpOvOuxj7PEGILG8X12sN8Xq5bCKY9mbuyFvLlIrDdfW6/ xa4gdkVDZ+WIsSMP4TN3FjZy++ZuCKcoLJgDc+Hx369tsqJ3Qwmdq1Is6CAc0coF4m7b qt1s2AO6kOeSi9NCQUdHsmXO+unq7+DiZnuXU+YzPd8PX3hK19I3Gmj9pN9tLk/M9nE1 Wdxx/VQFXvpVp23mdjwcE1uzIB8hpvF6lb0+0STggX90Reg3J3Tv0gz0fTvLc8Rz+rd8 dG13LLVkg2eBsO3waLf+K6dSRxU+7bxv7wOsRWwD800k8yQY8m4B05f8yIu+ofkLTIVn xfhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=POmAXduJ6SI7RVAAlYyvfPFre0sPrROg8vVQxGKuQEo=; b=iQJqryzVsX1/effBGRDWA29druIcyH7MRJsL31+0nY7VdfglQ6HVZ5MP3xQVytth/O zTNXdkBNH/BJUGA4+Kz1QgPOOk3AQwXyAj0W+HFdUfhbYRRijW/0qIuYoQ4dBnorHtmO ZU2/xTt6yYBdJSzdkr6KwH+AIseJRrR9ywnl7iS+loGK6TmU+ZflFqdODNq9B9ix/hBX 66pL2UCbnbpyB3+Uf4GRzwOrWBvZhTQxe6LUfsJ6rWvN6OioiphkxDk6oi4/4Ro+Dn27 FeYGZVyOtkcF2hh1HnCrx/nySEfhWd8OgCLx6NayL8UTP7goDXtTdYP8kOoBliSeTtAh s8vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aRtVmJZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020a1709028bcc00b00174ea015ee8si4164097plo.592.2022.09.28.01.35.39; Wed, 28 Sep 2022 01:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aRtVmJZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234026AbiI1IPo (ORCPT + 99 others); Wed, 28 Sep 2022 04:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233536AbiI1IOi (ORCPT ); Wed, 28 Sep 2022 04:14:38 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92B6410C; Wed, 28 Sep 2022 01:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664352871; x=1695888871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fusilmdSQD+FIBKYeUukiHJrxKRQ3B5pPSTTQeO8rTk=; b=aRtVmJZP3dhWAMYy7vGcUpqZwcujmTa8Kc9fXWFcLVS/dPSWK6Y4kRZp 5UGBc+T+jxOTTlDpeArjG2wXxWhf3kWCnhyYZTbTUjiLld8eSnaVkcRyR U7FRjuR4sGXI7Wd1dohCMbUtB390VDD04LWQVYEr6ZAgvWjXihM6d+NWg kodgxHWBOWebCYyxIzW4NY5P+I0tEfoIzq8Cc5b9PNAp1HhYfU24UhJKQ +GCsKe/zbz+3nW5JgSZ6tvtB142hDh5GQWmNPOuM6j0qLPPVv00B2S4Co mLQ5nO2qI4xNXSEvwCdx23liYWbhj1fOY60WJj7Q03WoUlzkMLtoXGGPR w==; X-IronPort-AV: E=McAfee;i="6500,9779,10483"; a="303022875" X-IronPort-AV: E=Sophos;i="5.93,351,1654585200"; d="scan'208";a="303022875" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 01:14:29 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10483"; a="621836391" X-IronPort-AV: E=Sophos;i="5.93,351,1654585200"; d="scan'208";a="621836391" Received: from maciejos-mobl.ger.corp.intel.com (HELO paris.ger.corp.intel.com) ([10.249.147.47]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 01:14:19 -0700 From: Gwan-gyeong Mun To: intel-gfx@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, mchehab@kernel.org, chris@chris-wilson.co.uk, matthew.auld@intel.com, thomas.hellstrom@linux.intel.com, jani.nikula@intel.com, nirmoy.das@intel.com, airlied@redhat.com, daniel@ffwll.ch, andi.shyti@linux.intel.com, andrzej.hajda@intel.com, keescook@chromium.org, mauro.chehab@linux.intel.com, linux@rasmusvillemoes.dk, vitor@massaru.org, dlatypov@google.com, ndesaulniers@google.com, trix@redhat.com, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, linux-sparse@vger.kernel.org, nathan@kernel.org, gustavoars@kernel.org, luc.vanoostenryck@gmail.com Subject: [PATCH v13 7/9] drm/i915: Check if the size is too big while creating shmem file Date: Wed, 28 Sep 2022 11:12:58 +0300 Message-Id: <20220928081300.101516-8-gwan-gyeong.mun@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220928081300.101516-1-gwan-gyeong.mun@intel.com> References: <20220928081300.101516-1-gwan-gyeong.mun@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. v4: If BITS_PER_LONG is 32, size > MAX_LFS_FILESIZE is always false, so it checks only when BITS_PER_LONG is 64. Signed-off-by: Gwan-gyeong Mun Cc: Chris Wilson Cc: Matthew Auld Cc: Thomas Hellström Reviewed-by: Nirmoy Das Reviewed-by: Mauro Carvalho Chehab Reported-by: kernel test robot Reviewed-by: Andrzej Hajda --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index 339b0a9cf2d0..ca30060e34ab 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -541,6 +541,20 @@ 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 BITS_PER_LONG is 32, size > MAX_LFS_FILESIZE is always false, + * so we only needs to check when BITS_PER_LONG is 64. + * If BITS_PER_LONG is 32, E2BIG checks are processed when + * i915_gem_object_size_2big() is called before init_object() callback + * is called. + */ + if (BITS_PER_LONG == 64 && size > MAX_LFS_FILESIZE) + return -E2BIG; + if (i915->mm.gemfs) filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size, flags); -- 2.37.1