Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp59001rwi; Sun, 9 Oct 2022 18:27:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yfRcUGwQPelhaKo7FRi0VYFusKYfi3wKOgqOuI9r5gJ1orLq4h1ggY+0TryIJgqgeQyYF X-Received: by 2002:a05:6a00:10cf:b0:563:34ce:412f with SMTP id d15-20020a056a0010cf00b0056334ce412fmr5560305pfu.67.1665365267184; Sun, 09 Oct 2022 18:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665365267; cv=none; d=google.com; s=arc-20160816; b=nxMfzSfXd0jw2v20vMCw0k7Rw3WZFV3IAzsQ2F+OEgEHJPOmCPyClkAdMkgzTpyu4l PP7HiELe4ON0ELi1woIvp08SfgDHRDu/SS5Tm9IXWsmhj7/mCZZsPvMZTuGSkAfQchEk Q3MmIQIxwmAdeeuElcRjjl49MIfKOspI0oAIv/TH8g2gFwYpLfUeJEBHA4AEd7ejlQmF nHJftQjVAvuYpBK3X/EtyF8kzaXBnU499wRqUMt6i9Q3qr8Euh+TKp+uPrxtc2r1MumS qBL/6y70MDyA9ymcPgoSQYDP07cXFGckGvl7h8roW/vBMR0EJF3OQ+dN/QnEx+2YkfrV 1O8A== 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=aByqvEg3z5aOYYnX07dH/5q19AGb7yJ4k/1amz3++rs=; b=NQF58dAK0KDd+QssQVo4QgVQXfAJTBNaUBaZXNtSCzj8Qn+Urrt5IRo6pM2NYtlDfA G4M09E3xS/XsLvfelEwtq2uL8Oik/AE4h0gntLxz6kH5s/VF0KJFe9+aCmzxiLaDDRhr +c485kh2XCnoaoEZmUZ7JON1As2LRor5P+7Le29jc9fuyHhW21ayls/SRg4IkjR0HbVa xmmShwnwqYczFeA9W4E9tEXCCThyxgwhOxgU4z7oWT9q++7yrLRdXnpBMZa0LPNz+nnR ZhnyvA1xwaA+t5WKDcKYRdF3b6mS8/AVV2eNQxcrN5hshaCNCROWBBQOWrSFq4ei/PpM 0XJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pTQnAsFJ; 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 t189-20020a625fc6000000b0054246220a40si10951429pfb.158.2022.10.09.18.27.35; Sun, 09 Oct 2022 18:27:47 -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=pTQnAsFJ; 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 S232560AbiJJAVY (ORCPT + 99 others); Sun, 9 Oct 2022 20:21:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232420AbiJJAT7 (ORCPT ); Sun, 9 Oct 2022 20:19:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CFEB2CDFE; Sun, 9 Oct 2022 16:54:31 -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 dfw.source.kernel.org (Postfix) with ESMTPS id DFB5060DC7; Sun, 9 Oct 2022 23:54:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 457E9C433D7; Sun, 9 Oct 2022 23:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359670; bh=K928hggqmgw1Pg5XlNZonUznWtzyojN55Y/uyUIw7uY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pTQnAsFJ/hvG+nCHLFFtszt+zjAy8fpCaiIXHpS2SfOK4+IZ5IsZHA7Tb4oh/DrSi xK4wbj+tsydVPnOC0skFezLOD4u28rBfgZyG5bG+p8LLeNv57smO4g0SFkWaHPrdO5 1ELyjtanqG/GJabhn4P+hTJSJm/Ec6g1IBzeDc253ukFsy0G2lBtshabPPiZ+cke6o 4xDREwCz4eJbDlH0JRP4YZ/HXwwAxyH1L07WPpkw6nemy2pwYeqX64ZHMTShe2QA66 Ot059s7Vbwx6G8ChomQywj8XJLk2AD440cWEAQYfO5pNN5NRKGp4eoPMYaLsIV49IK 9NisNMz9yzVFA== 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.15 02/25] drm: Use size_t type for len variable in drm_copy_field() Date: Sun, 9 Oct 2022 19:54:02 -0400 Message-Id: <20221009235426.1231313-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009235426.1231313-1-sashal@kernel.org> References: <20221009235426.1231313-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 be4a52dc4d6f..5669c6cf7135 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -472,7 +472,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