From patchwork Mon Oct 24 11:32:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp528084wru; Mon, 24 Oct 2022 09:01:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7sgtMHGuvBpCnASpo0sEX1oCfsGL7nDPb1GAjIhdy6GUM3GYFhTlGQL0EVrsYamQBE+vbf X-Received: by 2002:a17:907:7fa5:b0:791:9a5f:101a with SMTP id qk37-20020a1709077fa500b007919a5f101amr28191113ejc.453.1666627303571; Mon, 24 Oct 2022 09:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627303; cv=none; d=google.com; s=arc-20160816; b=AKhcNCCizNWHH352442H0X0ZEauBTYOYiJZg9xLwE5bI8L79+rJzBBDnMwHgokvGa9 jvCq0rN8dvwFdsNz8kKLsBi/i9r8lZdvfpsMVY9a40pCryalWENfftj6SSOrN0TPXk+g 9pc3kgDVooA57Ey57UJWXR1nlHzzZXCJGNbsTH+/4VfNiQjaAx9I5C60Sf9GMZoFzwX9 by4jwGV3dK1MHbRKhbT7CSyIWuJ+ogdEHthgMph84JKj3ytIxkmomNzkssBSRYld5puu 7I3/6awpbqeF7YPk88CXea6T/Tt7NcAJvssEu52iAIhecphjc5041F6bsSLjP5p+WQI2 9zWQ== 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=dRKjkhxSiXyCxMoxVXdjbs5O9+jTCf3iaRIi6A6J8JA=; b=NbCXZ/ueBiZCZdClP/j8SGP+rd063grj/93sGeNWuDmIXfqIylwxlCSQpgOjkTgQNL jXVimMOYREMP68e5b+oKz37tXvK65A/G5RCPOTAFInAJCc9Ez/6g+x9tmmbGs8dAZvFV tmvf1gewW7Hj+O6t1Nl+2XFkb4I4tc5zP5H8XlGnlLOipzVp+CVvTefDga84hrDyVsk6 IbmfsCWqqHOoWcHsdHgqrfitEqPN3KmwiVdkmALS3tsP6QkwVoMVXDLY/JOTy/biQVkE IDazxujfsTzhqJJa/7JI0m/mfCBMuaxP/hu5yABLIg/5os1Djes44Bq6+zS+d2Bs06k0 aMQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cqbx1Nda; 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 g11-20020a056402090b00b00461c74a07c8si156423edz.343.2022.10.24.09.01.16; Mon, 24 Oct 2022 09:01:43 -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=Cqbx1Nda; 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 S229679AbiJXP7f (ORCPT + 99 others); Mon, 24 Oct 2022 11:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbiJXP6Q (ORCPT ); Mon, 24 Oct 2022 11:58:16 -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 60439AB80F; Mon, 24 Oct 2022 07:53:25 -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 1A08FB816A0; Mon, 24 Oct 2022 12:30:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73C8AC433C1; Mon, 24 Oct 2022 12:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614607; bh=UgTu8csKsVfByuJaIAwUtmNsQx8OeEppTNvLnEVGaeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cqbx1NdaksUjfD4iQDNqCX7TZvaaYX7kX+x6MHYRpr+N7pq8J5Oja8qbzfji3FEI2 Ue4W8AFtWnvGemDFZO0PBdP2+OWTg20d0dCqhbn0/5W26WzB+Upp/2YQs+66xX0+Uy 0C01G1cuMRGc3G6XuJU150VdNFlfMlVuNWQ6GLkk= 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.10 326/390] drm: Use size_t type for len variable in drm_copy_field() Date: Mon, 24 Oct 2022 13:32:03 +0200 Message-Id: <20221024113036.888486566@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747585391745933955?= X-GMAIL-MSGID: =?utf-8?q?1747585391745933955?= 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 4606cc938b36..a15d55d06510 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);