Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp56751rwi; Sun, 9 Oct 2022 18:24:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rQzW2PxBfmABcrQtlxw54R9m6EhsBG38ySoJ6hKFpuZ1dyMIrdWk1UUmiaPWs+3tuSg2a X-Received: by 2002:a17:90b:3ec1:b0:203:5eef:fe1e with SMTP id rm1-20020a17090b3ec100b002035eeffe1emr28461874pjb.143.1665365070738; Sun, 09 Oct 2022 18:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665365070; cv=none; d=google.com; s=arc-20160816; b=zzfNej9iX6Mi4CTTcU/TiUOn9ue3SIYPj1Mn5zH4jfjpDjK7hki8D7iGrgTCkVYxKw vpEW5aGURFlnk5so+K1akpp3dMbV8LCY5nP3UFiyhcQkaTJxnSDz43SRxvX6Pb72ZtEt 9cwLDXKtNpGpXZtg5oieXWCRFuMlPC6XCtFFDyFxUiY5+28T5D3/v3pebvsIJrj8UptA Gnf0UbJO19jjIDGeXInZfCHw6Re/MKA4B8D9Q8pGLnUCeKA2OMJqHCejjPnbMoWpYI34 rzEFqNR7yXrSywbGtlEdQyqZ6mbmt5JScCnFNKeNfJHKCDNvauMNQOVEzEJLeC8r//zo 34eg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=D8phQkkkzlcOiymb7+gznCaX/n+tQLFWIpnaz5lCqK8=; b=SwzcVqRkR2tt7YleSWVrWfnVlwYSwW6iAFiGprIxjyaGzDeTJ5FO2ECP9VRjyjj97E KgfFTN5sCphyqucavwBJU/3f2+kD+r4wXnkYJbTxQw4+WnNwEreN8uKey5C/QFlA0UiY gHRxLBTDV+BRg5gShAD+W3TJKXlCtRNQ4BvyIO8rhcWMwiaygw4ITsNxu0Xh4iuqJsEM +NnyggIUIf/NRueSuJP42m+Xj9uOIj/Viz/IJMKBiaS1am24EVhbqRCXG6yaMXdP9Sa3 Hj6gdIVNZUCcxfrtxsnIow6s8aCeGEwDXpZGQoKVTJDTGOyT4eJNgmRMJZn7uKC7QGDw WYkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kdmzkt/W"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020a631a4f000000b004347b49d045si11224482pgm.631.2022.10.09.18.24.18; Sun, 09 Oct 2022 18:24: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=@kernel.org header.s=k20201202 header.b="kdmzkt/W"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233242AbiJJA3M (ORCPT + 99 others); Sun, 9 Oct 2022 20:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232940AbiJJAXz (ORCPT ); Sun, 9 Oct 2022 20:23:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A1C25598; Sun, 9 Oct 2022 16:57:50 -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 988EA60C27; Sun, 9 Oct 2022 23:57:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C99ACC433D6; Sun, 9 Oct 2022 23:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359869; bh=n5ji/6Rvcj9gwglRBVe1y6EZQDOybbfeuTH2XpQ1AzA=; h=From:To:Cc:Subject:Date:From; b=kdmzkt/WkD1sqjPqSWGCOMlc/LIrGKvKwHMrz9DnNRx9NI2rrjEWa5hImBa0kqNX8 Eb/LkDqQLCD79jAED+e8xwaudwir27REmPhYDr79n9BlfD217+NlsQBZHJ193njLTs R8cv0AHV2Dd+TbGe6FVrG66dBx3XSZWIHxb0mKCjOMcW+fx71/PSQIQ+8F+8VA7JjL rvnfU9Qlq9/tAKebrt+DlCmjHGffQ76SeYN/d48Hhwzt2LbvnhugdDO5bTMaIzafZ/ ieCAVHP/mu1fSbbIQWBOe6y68LFezziLF5Ff+cACtYt/SDslApDT9Sw09NgUVGOsJ/ UHvp29YvNEXPg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Javier Martinez Canillas , Peter Robinson , Thomas Zimmermann , Sasha Levin , maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.19 01/10] drm: Use size_t type for len variable in drm_copy_field() Date: Sun, 9 Oct 2022 19:57:36 -0400 Message-Id: <20221009235746.1232129-1-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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