From patchwork Mon Oct 24 11:32:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp545344wru; Mon, 24 Oct 2022 09:34:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PUNyM8i51Eba89zWFiTwZ3E38ZwWU61q++cNwIHgXJHjfNuXkDTP1cY00DdEbqbwSiqe+ X-Received: by 2002:a05:6402:2793:b0:45c:d273:8c18 with SMTP id b19-20020a056402279300b0045cd2738c18mr32616413ede.337.1666629254101; Mon, 24 Oct 2022 09:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666629254; cv=none; d=google.com; s=arc-20160816; b=ge/necpS0TFG0JPwS8A6JobnjK5MotF3U8acii7aK9Kxhjqy6ugsZZ8w+kuc4lEoN5 M8JjMAcxJSTXfNKkJ9JKKMVsn/2MtRZ0VjWoGR7jVXw7gIBc5sRPr2ntBwpGjrnG9qIX C554T/rEhnUg/iB8GqvnC+V2fn49kfCx9o2Zx3fAO4BpcmvEIv0wKLvf/ZdkCpbjNXJK Edcpb5D6jtga4t+i3STIqe5eyaaLQcS8yv2B9x7MUISXz30SfL0C/Ny+QZ/GaRWwDCGf GmxP25VpoddCKhE8W5D3tq+5WcA1uH6UTWNlX3mt7yGOQK+htGwDeJytuze0VfLtb3ll VvdA== 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=UiKTA0mrOAXPk35GCK2na4KqXYTfmK1knzk7dia2+RM=; b=xVnDPmRFDiqW6RxOyUOnBBFhikTfWNfTtn07HDTEBsMNLGoomqRuAe+ww7/DmlgN00 1Iieq+96dYdL4a6Hrt484MjDr8oCCpQnmMwAV47m1DA5+hshCApA1h00he7ylah8J7Wd nbHpID09qqv8cWix0aYGZ5Az86LTQQODrouGWqTU9LVzxU8a5ZhB6sa7mYiE/dX/DLU6 9Wr01XXBwAcCbo5VmPYMjY4KNLhJKWllqdTEBsH4EXYs/atBtUUteolJh+qtt+aozxgA cbbh6CgABX0zdS3TMsexr9KYhtTz/ZVDVRwZgKWCjzGhXKCyPbjD4etgAeiszHHAoiw7 0kcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yWsN/mXI"; 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 go15-20020a1709070d8f00b007879bb73291si145232ejc.807.2022.10.24.09.33.50; Mon, 24 Oct 2022 09:34: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="yWsN/mXI"; 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 S229817AbiJXQRZ (ORCPT + 99 others); Mon, 24 Oct 2022 12:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234981AbiJXQPg (ORCPT ); Mon, 24 Oct 2022 12:15:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE0374A818; Mon, 24 Oct 2022 08:03:23 -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 38871B81613; Mon, 24 Oct 2022 12:13:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97506C433D6; Mon, 24 Oct 2022 12:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613635; bh=ymqqx1RvVFDAG+2fiPlsdd2DsdhocIdcqP2p+8HU/t0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yWsN/mXIaeV8SHdzv4jK7c2MMb8lgdj6oCFES+LIdWkyo0dtL+TPDOg7RXNWIfyCa qyGzLZnTQmV92YXEeO2Ny+O5mQpZRG+iP2rHYXoOvcbuSyWp6PxzeXv39paAd7PQpE yZNUils4idcw+0Z049K89P+dLNIiwUxYfy6anV7c= 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.4 211/255] drm: Use size_t type for len variable in drm_copy_field() Date: Mon, 24 Oct 2022 13:32:01 +0200 Message-Id: <20221024113010.055053979@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747587436559253241?= X-GMAIL-MSGID: =?utf-8?q?1747587436559253241?= 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 76b6676b0106..bde71aa67784 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -473,7 +473,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);