From patchwork Mon Oct 24 11:31:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp421809wru; Mon, 24 Oct 2022 05:21:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6IGzKMnjWNc/Gf7dIMjgLR6ygC5XWUuf/QMciZ4tfl9dqksIepQFaYk3MBYsEslT2q2rzn X-Received: by 2002:aa7:c648:0:b0:461:d9b4:687e with SMTP id z8-20020aa7c648000000b00461d9b4687emr2795233edr.91.1666614074349; Mon, 24 Oct 2022 05:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614074; cv=none; d=google.com; s=arc-20160816; b=R13JQQJ48SmJ+k55l+GzBwMcjjJtsPX3EIcg+Eemh4rNI7kwOiQ2uj1gRC8Hef77I4 o13srnZU6pglIHHYaNn7a4EHmbmhv0h/gnWVbhur/bHbbSIR5DmtyEfXi/Dw+Fa7uQ2E lY3dJmMKLaV9avXzcDj8qMDwjjVUuYEKCI54BTycslXR7q1gPw13JWEZ2UEPuSQ+JlzI ZJnPkTlQR3XXnaOinrTaELBJMGVJ7aB8OUJjxpI3TM9AokrtsEqqgmQrm3hT4p1COHXB +iXA8PE1hGj6Smzlq4szhWfwjwGA3mIkCRy/9zFgJ67Mktti8s0cBXQZqa7qK/PkcskT DuKg== 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=HG0/DUbcaMZKb0DO+oOaasSUSluEzA9ip17TOkSQleU=; b=afUFepfUmFc+zUUAj+a8tal26vGDuc5dHMsBhF7/vC7JgC7nmkzqG7jbQf0Wa6MfDR Lwmb6pRm0P9tAJVc/KQm7ywL3LkG+HuGEXmEmzs9OGhguys0smRKUmtV22DdFeXBoyBC w6CVm+5cLM8mJuZ017NqdA+3fz4bvHfHNr1R6jIa414PKHxBkVGNuXG6SCjFd2R1/8yN ngNLH7uH5wT9oS8PSi6GrVSS/KQ8ycuhDaJ0VOenQia4T16KGjnM34xuRJkdrszS+R6T dPef9dBbQvSWusqh219jY0oRLygqxBrUdhYiMSyGeXA8CVvg38D9kZfYaQTUFfabgQHZ hFLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bO3cxB0V; 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 eb13-20020a0564020d0d00b0044611122003si35655467edb.599.2022.10.24.05.20.49; Mon, 24 Oct 2022 05:21:14 -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=bO3cxB0V; 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 S232994AbiJXMRR (ORCPT + 99 others); Mon, 24 Oct 2022 08:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232970AbiJXMPc (ORCPT ); Mon, 24 Oct 2022 08:15:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F757A75D; Mon, 24 Oct 2022 04:56:14 -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 4CB65612D2; Mon, 24 Oct 2022 11:53:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60E88C433C1; Mon, 24 Oct 2022 11:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612399; bh=dkDStA/N5coBfdpr+Nbz6hKHmobdpXDdiQ3lUfUMJpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bO3cxB0VRyUhaqxSa5YZtZwcUd6s+xcQfq3aHVH7u3oO/TyNlITMAAsd+I4D4zrWT 4LN047wNX6DjOm4SGGGRAD5ZgRI91+pOaBhn6GTXPZMrOEi/LWvmg1+kvE+VxCGCMj sVNfWWhXF0tTw+g1dhbWHqNVNeqvBaERi4ZS9xHE= 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 4.14 184/210] drm: Use size_t type for len variable in drm_copy_field() Date: Mon, 24 Oct 2022 13:31:41 +0200 Message-Id: <20221024113002.927118752@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747571519363163715?= X-GMAIL-MSGID: =?utf-8?q?1747571519363163715?= 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 ce26e8fea9c2..335fad8b209a 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -437,7 +437,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);