Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp78984rwi; Sun, 9 Oct 2022 18:56:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Or6V++2dl3iC+13GHIDWVsJqkxoMsCES6t7hr22gW65JZrrjtdmIZjjBu3HiGEGrfFkxF X-Received: by 2002:a65:44c1:0:b0:428:ab8f:62dd with SMTP id g1-20020a6544c1000000b00428ab8f62ddmr14713143pgs.211.1665367012006; Sun, 09 Oct 2022 18:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665367012; cv=none; d=google.com; s=arc-20160816; b=o3xKoIRjzPEcSV3Y7DdqoZKVDH0xkKLrJ4roNlzM+UJA4sMQwA+SJbm7o5cvNhoDrg zcw+5n7mNWB/hlYWKTolKGn03yu852IeCu4A0t4FwlEJuANoGtXk9GZns481E/BC+jGG CEz8M7CiVXhC+9OglnR4Pwzv3RH7I3cPx+cr7KMo5nHH1j2Kj/ct20ESaQkVMNrQHhng RGMXCjl/gUdYv7AiyxAjFEASM7ym6+gbUMZxcpYeEZKOlVcZ0P8lbs0TK5TvaupRQYYj zeoycGH2PnOzVFXCKN6OBJ15M0X7cBJyYOV5ISaoxMSkaImkWf2nbzKqW1t8ncM1NqU3 UMzw== 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=UiKTA0mrOAXPk35GCK2na4KqXYTfmK1knzk7dia2+RM=; b=fTin2wKky9rwOD0oDaJ3hfkzrO4DyAfMApiRJb65j/PEthUh8887aLjlkT193IVUqU PipF+ylY5ohBErzIfAkmrugphjmyeQQb9DY2SPeWsp4Qeoz+UA1d9epIeAMEFZ51Ck2V IemltZwkMZe7sQD5ZSSUleMEpvQE7TUS9GPvieZSFC1S7uyv3QnWN5LK8wcZRGMaWdeK kS2175ru6/+p1Yh00DANl6/evgyOZc5GdieOQ+3JR0z2kzmlT6o0qL0YWaPTGldyJ55m BOlXsxHijtkPMoKMo+QPUrNEnp5UgxQ1C1IBFtAf8c/oX1Dqo0VLxALWLThsLO2OrASB QhdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uJ4gH1v1; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020a631b15000000b00439e032756fsi9845444pgb.65.2022.10.09.18.56.39; Sun, 09 Oct 2022 18:56:51 -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=@kernel.org header.s=k20201202 header.b=uJ4gH1v1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232710AbiJJA2Q (ORCPT + 99 others); Sun, 9 Oct 2022 20:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232880AbiJJAXv (ORCPT ); Sun, 9 Oct 2022 20:23:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6C14220EA; Sun, 9 Oct 2022 16:57:17 -0700 (PDT) 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 5B3B3B80DDF; Sun, 9 Oct 2022 23:57:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0594CC433D7; Sun, 9 Oct 2022 23:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359835; bh=ymqqx1RvVFDAG+2fiPlsdd2DsdhocIdcqP2p+8HU/t0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJ4gH1v1K9zXUZ8yqZxmo5T1+s7DqEqwh1B4skbeajUJEhn4VPXt2vVKrI3NHjzHo knorCkg6BQJOPnzvby0q7ILDGsZqS3l2rhU5CIqsQ6IVYYU65JTKZdJT1QUhCjOerR itFfEjm5pIUSHkwNoI0tGG+EVwrmzxtRXFD/Z1q6TnLfYyMHs5ncLk1+LCzsqJzMxz e0txocVrYDLAXM7bu+MUyoLUh/bK/NlDyrtNzyeyynZHRpiCY1/xRY3HwKaEOMLxxN mXyii+sm5V5A+DdxDkjByRWq6Ac6wfrqek8ula5dMVxbpXBMu/dnd401n0L+U+/wyX zBaQRykoXqooA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Javier Martinez Canillas , Peter Robinson , Thomas Zimmermann , Sasha Levin , maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.4 02/14] drm: Use size_t type for len variable in drm_copy_field() Date: Sun, 9 Oct 2022 19:56:58 -0400 Message-Id: <20221009235710.1231937-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009235710.1231937-1-sashal@kernel.org> References: <20221009235710.1231937-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 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 76b6676b0106..bde71aa67784 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -473,7 +473,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