From patchwork Sat Oct 22 07:27:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1108061wrr; Sat, 22 Oct 2022 01:43:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40DtTxYCH/+LqK2/kpr8SPJvb89v/duSOqravPnI+YDps/rVRvUdNN1jiPD3BhZ7XvzDNN X-Received: by 2002:a17:907:e88:b0:78d:fb98:6f5d with SMTP id ho8-20020a1709070e8800b0078dfb986f5dmr19326244ejc.5.1666428191402; Sat, 22 Oct 2022 01:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428191; cv=none; d=google.com; s=arc-20160816; b=emCkB8eVzVPWt43Np77xF+NWzD7uNVtLOHEldnQ3Lp3sWJty+oZkTGq1zaZzrxW9lY tj4J+onhe7K4ioljxG3j3yZ4O5KMDFEPVITAktkj5E+NzWTqA65niZgSVoHCx/6osEG1 H676ZQey9FCzUWvpfvj3YETmsDDbLoOFLlUbFCLh+s88b5DhpJn5+Iq7dWbJwhSiLlLU mn4T64BefY3Smy3UMdFA9V+apYOWRJWDZR+1p76HZNyWkW7pISLyt5pI+890sa/oWLpH MVvPPi6llbmzvnE4OaT7x5Uc1Q6sc1Vx0cKdjiaOv40OZj+zly8Fo3taMUMFNl0EjW8C c9/Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p6i0eXXtXMN42kDKXAlDsESN02WWjm1DtOPHQaTy9CU=; b=zErfmwkWcyo/sTTZRfM0uEh3kg0qSi4/KEGxBAfFfsUjkXsQK3MjK8xg71uqukDkS+ a0x6TGgTdDzHyp1/JBvIT3Q0Sz1kJEHTucKjXzKJJArCmz+apRj5F+5FjuGE6XlhWe7b DYo7rDYUlQPoAcBZsAbGZjp9h4YgZvt+uGepTqXn7oBnH+Ffno0tPvKHMlDLT4SARf4V i+q1U+nqcsKHHr8kdLjYrkDv2QKmXr8ybKmsvQd5lM6TCFphCbXNSHFyNiToZxmlMtK/ 6bdUaY7vgjm/E96acUFmh0oLc1FmKHmBwyu2NFL1rc6ta4vN/UtaDmB2/PBuuhr9ja7j 07MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VXEadJPf; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a05640211ce00b0045d079c8f20si26613071edw.43.2022.10.22.01.42.40; Sat, 22 Oct 2022 01:43:11 -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=@linuxfoundation.org header.s=korg header.b=VXEadJPf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234636AbiJVIlx (ORCPT + 99 others); Sat, 22 Oct 2022 04:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbiJVIhO (ORCPT ); Sat, 22 Oct 2022 04:37:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B3A91440B7; Sat, 22 Oct 2022 01:05:16 -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 EF155B82D9F; Sat, 22 Oct 2022 08:02:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57479C433D6; Sat, 22 Oct 2022 08:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425734; bh=tYTHxkJc9elNPtIm0h1+yrKoky5BT8EYR9ItYSUXyG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXEadJPfj1iEggktPZYaZmH5lAMnja8pOhyEZ7ZJp/b3oSVrTgyQoiZ80BdCUBcXc cpIr1aADsgCr0gEixELSiPmcpgm0xpEdis8vi3tA7H35gW/Rgy12wRUkO77vXi1/tv wzpLzWKjWUCROmnKdFtiUjqNWIDQOnuXF7DtssDg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Javier Martinez Canillas , Peter Robinson , Thomas Zimmermann , Sasha Levin Subject: [PATCH 5.19 599/717] drm: Use size_t type for len variable in drm_copy_field() Date: Sat, 22 Oct 2022 09:27:58 +0200 Message-Id: <20221022072524.950296791@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376607296136035?= X-GMAIL-MSGID: =?utf-8?q?1747376607296136035?= 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 51fcf1298023..e6895699e696 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);