From patchwork Mon Oct 24 11:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp404896wru; Mon, 24 Oct 2022 04:55:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5S0Pgz6xGGC4bZvhHCvaib66QEuqS9DtLhoJv3fNkWihzHCCYHW5Uj9F1XFGUzby5dq2/5 X-Received: by 2002:a17:903:32cd:b0:185:5421:a5d6 with SMTP id i13-20020a17090332cd00b001855421a5d6mr33305582plr.99.1666612556876; Mon, 24 Oct 2022 04:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612556; cv=none; d=google.com; s=arc-20160816; b=I/4kojYnLyIRX74nfZf4lYBNBKmMs7sXi8OElCh776Qa4MznpG+MwiKWPKlakfD1Xc QjQYh+70or1wNZ4r82GoOi+gKp6SFyizEM0qKqHc93lCaj94ZFQ8gm8P8CLq9mXHZzx7 cfez1ZsF8rV78kMHxwYwOmHLMv+CWFrRg3AuK8ri31kVegO80Pf9/DzSqpqFcmygLHx2 mZSGMJnhZCFNm8WR+2jUts64hDEfECdTlIzIhiXJPwOkWixDEPrKaeLC0y2cPcnGgi2x 9DJhzFUTaSB0W1KondzUoB60xL1ihryCppz/nvkzM80c+S2A0fFNHLZyXqTZL56XEwfN 6rLA== 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=xKmn+I4iZsYUw1MgnWedPYUzhNvWOBKnALtoYlLcf5c=; b=FCT/xDqec4Is/SQS5PXjVzJQUYP2f0Mxlc6smyOfDU1Q3/cTxUEPpiNFnRNAhWx5rQ 03pYlmiJC3adDunzW8dNQN/McK/VC/+kljSospRNJbyk++CIw4gx4UdUEjAeNb5N5omv xT9lAvyOfFcrktk23UzojksqJRrMa9TX5LSEalB/o70Cnya/onQxecDCtHukr6N8uxOu R9D4vIwKRhuO3yWgVK4ZnkBgU8wdFXwhL4hW7w6AkDKYqFIfRETH+lKrbvkDneJC0XvO YKeOitBtBELgtcEWoA6pbKX09fNOiMI5Nits7eR0V2Mm/yimaRgmAL9p2VgejkOBJ+dU A3Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xt4U7kpM; 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 192-20020a6301c9000000b0044bf53e335dsi34289996pgb.767.2022.10.24.04.55.43; Mon, 24 Oct 2022 04:55:56 -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=Xt4U7kpM; 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 S232113AbiJXLza (ORCPT + 99 others); Mon, 24 Oct 2022 07:55:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232366AbiJXLya (ORCPT ); Mon, 24 Oct 2022 07:54:30 -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 0CDAE78224; Mon, 24 Oct 2022 04:45:38 -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 D84F26129E; Mon, 24 Oct 2022 11:44:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC95CC433D6; Mon, 24 Oct 2022 11:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611857; bh=pM5RMo4uAMiKF6X+4lf7+U0OlbszhbcSfGki5iniq/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xt4U7kpMSjBq+ebNe0qaeKY0Nnf0DTVRS5vgxwA2gqqhU7IBdVp6duQqnAtL0CFB9 B/9pZ9YgHJFSYwUuzcobxS/xtHK1p4TZbMkZqnBl8fm1QvO1MmCmFwcp8pBtd4GlBz 5AYYF/XcX+VZ34DHPetmnynIdRNftnEFwd2SZ2/w= 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.9 137/159] drm: Use size_t type for len variable in drm_copy_field() Date: Mon, 24 Oct 2022 13:31:31 +0200 Message-Id: <20221024112954.471188121@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569928753465785?= X-GMAIL-MSGID: =?utf-8?q?1747569928753465785?= 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 04b26ca06180..faa084ff4f17 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -419,7 +419,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);