From patchwork Mon Oct 24 11:31:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430946wru; Mon, 24 Oct 2022 05:42:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UvSKfFkCl8RWUvjZCAAadaDZLgY/rzF7a8XC92xHUplk/MHTNHVlDJtWG+iMWbOwIOPUv X-Received: by 2002:a17:902:6b04:b0:181:5dc6:5348 with SMTP id o4-20020a1709026b0400b001815dc65348mr33308719plk.69.1666615354745; Mon, 24 Oct 2022 05:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615354; cv=none; d=google.com; s=arc-20160816; b=XPnPm0M0jMyXXZC7J3hBk8Ytav6xmRgbAOspjpwRONQ0WfYc44v03FuA70u4M/jSus f1RK5lSuOYmC2qesfnoo6csFGu16m3CFDDPX0mbbLiSytRMSGVUnzmh/rmxbyKyCEgat /yVUsdaqq0oqWcDSTcmNEUXYCF8wjQlnDhXcaOhVODGZoOUpLYaHi5yAT+868RpoUQSI MPA7xrmrXBq1lic6Iryheu6BZIVCtNo41F27uakfjC/xMUw3g7+lSHqT5lirGywGSki9 InAGwwslY744AXfFORI5R0sVU/QdpsdVtluIKt7bl8OlgYL+exHrekL1d3rjkCIMtFmn 06BQ== 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=D8phQkkkzlcOiymb7+gznCaX/n+tQLFWIpnaz5lCqK8=; b=bZNM23xyvAeeXPYD2XdxTRZM+x0ha/Rn9d3itH9LJ9n+7Fvg2fFDQKwMSZAh3CEv0d 987NhcL65saEZPa1jmhrYj4pMwEb9WX769SqZdZfPUOMdyufwq6qY0YQg5u9coXxgxf4 WHDtvAipQLkCMdJUnkMefd1VF4xiElH9cGHwAvkjJFj0+f+evD6xkMvvAMMsTwI7wOVN b4oBLUzF0TciDOIX9oRgt2rnbKV3NsIU2aRoQdY0+YbKL4NuUYxS8gcD78dC4eLpU5Li LzILfmvoAKpTH2sYfNJodNQy3Ur5Ks/td3TLCQ+CCfyccrm+omfwf/kS/qQvnweYxqLp 2m6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ieo7OnM5; 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 x13-20020a65538d000000b0043c8ce98a69si38211952pgq.711.2022.10.24.05.42.21; Mon, 24 Oct 2022 05:42:34 -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=Ieo7OnM5; 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 S234586AbiJXMfa (ORCPT + 99 others); Mon, 24 Oct 2022 08:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234253AbiJXM3v (ORCPT ); Mon, 24 Oct 2022 08:29:51 -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 41C6388DE2; Mon, 24 Oct 2022 05:03:48 -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 C893E61254; Mon, 24 Oct 2022 12:03:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC215C433C1; Mon, 24 Oct 2022 12:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612980; bh=n5ji/6Rvcj9gwglRBVe1y6EZQDOybbfeuTH2XpQ1AzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ieo7OnM5vxPMFYRxU+LDs2kImRH7VWIxXYmLlC9prwHfbXbDlQQ6EfUSZSDoDngoK 1O6TPq0vIfkjWoDgtehX+7vpW/vGgaAB5aRVMwhFAxEMFhWRxR38pqhfQWkkY9USS/ rZft0JTE5pCR1gVudbRcQnHka/5MyiHGOaWgQnHI= 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.19 193/229] drm: Use size_t type for len variable in drm_copy_field() Date: Mon, 24 Oct 2022 13:31:52 +0200 Message-Id: <20221024113005.372170248@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747572862124095866?= X-GMAIL-MSGID: =?utf-8?q?1747572862124095866?= 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 babd7ebabfef..4fea6519510c 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -458,7 +458,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);