Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 773F1C433FE for ; Sun, 9 Oct 2022 23:59:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E04810E61F; Sun, 9 Oct 2022 23:59:14 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id AA14410E613 for ; Sun, 9 Oct 2022 23:58:51 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 47EE2B80C74; Sun, 9 Oct 2022 23:58:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE102C433C1; Sun, 9 Oct 2022 23:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359929; bh=pM5RMo4uAMiKF6X+4lf7+U0OlbszhbcSfGki5iniq/c=; h=From:To:Cc:Subject:Date:From; b=MyjCM5I/AHmeL0/reO7A6tpg5KCq2R+vx0KGbktglwGpJu81iXMwaikn+OQY/kwct lJqoOpY64jn2Yzv57wFqbkdMkr0V2u0CDYwWPNYPTqlxd+nAXtguYNpE90m0s5cJY5 dsvN+lePn4K/FBcNNQBNZfT1Hk9SZZ7CRcy11lcAlpE9aG17sr/2BMbkOe4H+M3GeO riXzUEusrXY1NblA0HxOxFMPcSqqWfCEM/893y2BgUPGrUMQj/nGqqKbCcIwsCFDMc heVy+PF68uVP6iksNDmntc5BT5ocG1kZTBF7BnkBhAuC0giUN8Dgdcg8eNwyT2xiv3 8uCkPj/FOiBFw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 1/4] drm: Use size_t type for len variable in drm_copy_field() Date: Sun, 9 Oct 2022 19:58:38 -0400 Message-Id: <20221009235841.1232395-1-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , dri-devel@lists.freedesktop.org, Javier Martinez Canillas , Peter Robinson , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Javier Martinez Canillas [ Upstream commit 94dc3471d1b2b58b3728558d0e3f264e9ce6ff59 ] The strlen() function returns a size_t which is an unsigned int on 32-bit arches and an unsigned long on 64-bit arches. But in the drm_copy_field() function, the strlen() return value is assigned to an 'int len' variable. Later, the len variable is passed as copy_from_user() third argument that is an unsigned long parameter as well. In theory, this can lead to an integer overflow via type conversion. Since the assignment happens to a signed int lvalue instead of a size_t lvalue. In practice though, that's unlikely since the values copied are set by DRM drivers and not controlled by userspace. But using a size_t for len is the correct thing to do anyways. Signed-off-by: Javier Martinez Canillas Tested-by: Peter Robinson Reviewed-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/20220705100215.572498-2-javierm@redhat.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 04b26ca06180..faa084ff4f17 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -419,7 +419,7 @@ EXPORT_SYMBOL(drm_invalid_op); */ static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value) { - int len; + size_t len; /* don't overflow userbuf */ len = strlen(value); -- 2.35.1