Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp3165569qtb; Mon, 24 Oct 2022 07:12:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM58Bj3VMBcHKvH01hQA0ESAOPiJhfeA6GVYxZ1oQURrph19RnAqnT4Qf/QEj5T/MoZvl/5Z X-Received: by 2002:a05:6402:2989:b0:44e:90d0:b9ff with SMTP id eq9-20020a056402298900b0044e90d0b9ffmr30855294edb.110.1666620738745; Mon, 24 Oct 2022 07:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666620738; cv=none; d=google.com; s=arc-20160816; b=vBmAta4GqtDdzYrCQaNbUOrh+/D4HqlD+xTry9oARMrYD07viZSbXJ0DeCAuKuNeAJ 3QLcL0BCQHqxHa+KA42FALTmefwQPfrDiu8VmX0uLz0bhIjOJNA5P42hlH29Svb7Vg5w LZWaa46vfVgrzutuRkmMLXEoJOQ4T1x9kwvQK8ulRKylImvnm5bCX3t5CG256XXTZH1W LxWFQf2Y0/e+tk8HAeoT5vVKTn0qLPVIn/k3Z+DUBSaHwK+qnsamFM3+ZZBzMb25Ntt6 u1wyDrzuZmqrH4UI86Sj3Kc4JsgGcWluZXguU5rUfQLshKUhGCL0VOQfDRbS1WkRPiuj ot1Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a1709064cc600b007a1084820f6si5396899ejt.230.2022.10.24.07.11.53; Mon, 24 Oct 2022 07:12:18 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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); -- 2.35.1