From patchwork Wed Oct 19 08:33:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp225959wrs; Wed, 19 Oct 2022 02:44:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qmVEQuxwAaNQ5bnSn/lYAD8EG6QEY3rKBLR5ABCF7R0dYvCnPSfkG5Wq1TxN3NvXMdzai X-Received: by 2002:a05:6402:27c7:b0:45d:45f0:e6c4 with SMTP id c7-20020a05640227c700b0045d45f0e6c4mr6469224ede.325.1666172670471; Wed, 19 Oct 2022 02:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172670; cv=none; d=google.com; s=arc-20160816; b=FMQMHp8gYxazSnNK/rHAVKH6ZK5YwYyKwSomWVqREVkvbmg+dzXKlCs5DxamI8+/ca U7AzhdhRcxTrobBImBIZbyNH9mxUtKXpVEnyLYgAyZqmULNxFh4kE8AaB4xggz2uLV6M 5pfydOknMZyu23inAlTZZjdAa65LiUvKk38mRcBMRwz7teTtLL49sBFhgZiBgka4g4RL Y7kZMz+TkroWY+TclfCYwsUfCI/KtDrE8c95GSKas5Q/jXZMyEaibnZAJqki4N5YkCou 8zrdIaWhH8X4Rc3Gm3YHTzfs9fQWEV4I8fFFzbAlxfw1Tq5ISaJYrxfc1QXqmWtSevEv audg== 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=A2hJUiK1YRKOZ3P4kX++exJfL9AzW8nZy2zW81ljdU4=; b=EuEo4hWqmykZLMlQK91c1YmSHlLAT8GM3MA4ORn53oMAXHcu9BMBuuS/Dg/6EE2vAh nNDNeJPL0Gs7hfCMBmG76o+6Fmilu4fZXbsG3fP/rSHbjZU9NxzlgBL66/zMDWUIYhyB TVsdhfgN8nqVzYckmbyyzhvRmp72cTdavEMKdzr+SnFvath8arwqGN6TgLoMcHAntcOB Y0G3eDo8QpDeeFRgQBgKrCZMwji5kVfY+j2TiT1BvxEQhUU3CzrD1mPl2+Mdu4EfRVsm FPDTTmz2/VTFXpdOq1aZIAiQuiPv4cTKVCsP1h+TGni3SgLPc/mxstZw9/pFgx66j+Bm /4qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LUW3NpQN; 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 gb22-20020a170907961600b00734b2821879si15382734ejc.898.2022.10.19.02.43.54; Wed, 19 Oct 2022 02:44:30 -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=LUW3NpQN; 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 S233537AbiJSJa6 (ORCPT + 99 others); Wed, 19 Oct 2022 05:30:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233510AbiJSJ1T (ORCPT ); Wed, 19 Oct 2022 05:27:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E966E6F6E; Wed, 19 Oct 2022 02:12:15 -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 21A966189B; Wed, 19 Oct 2022 09:10:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3097FC43149; Wed, 19 Oct 2022 09:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170634; bh=utuW3Bx0FnIKs6KiWMfFJsXZhlnXTIJMMLWht0Y6V40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LUW3NpQN3MCbhnS/HI2m6TvCLLIlnQSeF0CT923/hfxbi6qAIITVuJ3XQh5YHTQZh hpeADh5vW8ND4zUZnyqqp+INlD+0X9cbXFLUsmXCP9v3z03Ebw5nxlaVaytJDLn7KA q0K5lp4DZ3pEtgDcUNJaZgfDMmhKL68qaqywUrYo= 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 6.0 729/862] drm: Use size_t type for len variable in drm_copy_field() Date: Wed, 19 Oct 2022 10:33:36 +0200 Message-Id: <20221019083322.146268079@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747108674486160175?= X-GMAIL-MSGID: =?utf-8?q?1747108674486160175?= 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 8faad23dc1d8..e1b9a03e619c 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);