Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2218631rwa; Mon, 22 Aug 2022 04:26:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4M6edp3ZmBG5IvlMwQz2A22nxpvVAZ4dsyjdCyMVmBqW33lNtts4fhe3NBLE5fzpB9EyVj X-Received: by 2002:aa7:c78e:0:b0:441:c311:9dcd with SMTP id n14-20020aa7c78e000000b00441c3119dcdmr15500402eds.155.1661167570385; Mon, 22 Aug 2022 04:26:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661167570; cv=none; d=google.com; s=arc-20160816; b=ShYN98vsoaCZ1ZvkVuHZjUgzkVPvbxXWdIbNkC3+12h35jXntI8ctwXEQqpdAiQHMO xURRixYQup/jh553EqtAmnq1KN58GQykZtWo+9pTP9b1YvAms8pSNK80HHe0ZHQZ6tnw DjvPptmW9yHa4BACc0ralqw+dnquzLB8Lshfspwt7crAvu6hdIgUByBFx0kkLu4dbzNV FgkYBdhDM2wwv4n4rm4YydteiHn6QGgjOQp+uEJqOGl4wJTHnPM/oreKq0CiIeZmeOFM lD0IaN2isk1Ci/ryCZvDAAec/g4w2VbYULtMpxd/AhK+tAcESBHFHXTo7Bw3uS3Pi0GF 40KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=CfBJT/QTmBVPIRPqu/agoapkquNugkekX1ffjCA259M=; b=ZmM9pxqrOFsdQAFOvWCtehRR3HpMGmz7pRzRY9e18tUGY8F/x1nBhv+B2L8DMDEhKW ZmatX4ucEhbQzAa1OpEgA8roccVbRl821tfTuVQC1Fsu2Q7OvPUIC3iMINU8UP8v0Lh/ TX5jsCn8TmRKKJpw89wMjpN/+k+9G2I/LfMDq7H4KKH27gH1ka7rE+RI+9tD1902BKH4 JmzzQ7FNEAdhvWCmmV0NXdqP/Sl8cLXkC68wdbAS/GABYOSs2Gy4Lq39ITubcNrV6OCF r6T0ATZEz2be/2yba3JBAdkUacaH/c+d/EwiuMH1vqlZfhtvZekEM0gYEQuAHK9CjA4g k42w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di16-20020a170906731000b00730aacadc13si10858750ejc.993.2022.08.22.04.25.43; Mon, 22 Aug 2022 04:26:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233543AbiHVLPu (ORCPT + 99 others); Mon, 22 Aug 2022 07:15:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbiHVLPt (ORCPT ); Mon, 22 Aug 2022 07:15:49 -0400 Received: from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 594FA32BBA; Mon, 22 Aug 2022 04:15:48 -0700 (PDT) Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 1C0D11C0001; Mon, 22 Aug 2022 13:15:47 +0200 (CEST) Date: Mon, 22 Aug 2022 13:15:46 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Nimish Mishra , Anirban Chakraborty , Debdeep Mukhopadhyay , Jerome Forissier , Jens Wiklander , Linus Torvalds Subject: Re: [PATCH 5.10 540/545] tee: add overflow check in register_shm_helper() Message-ID: <20220822111546.GA7795@duo.ucw.cz> References: <20220819153829.135562864@linuxfoundation.org> <20220819153853.762825860@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="M9NhX3UHpAaciwkO" Content-Disposition: inline In-Reply-To: <20220819153853.762825860@linuxfoundation.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no 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 --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Jens Wiklander >=20 > commit 573ae4f13f630d6660008f1974c0a8a29c30e18a upstream. >=20 > With special lengths supplied by user space, register_shm_helper() has > an integer overflow when calculating the number of pages covered by a > supplied user space memory region. >=20 > This causes internal_get_user_pages_fast() a helper function of > pin_user_pages_fast() to do a NULL pointer dereference: Maybe this needs fixing, but this fix adds a memory leak or two. Note the goto err, that needs to be done. Best regards, Pavel Signed-off-by: Pavel Machek > +++ b/drivers/tee/tee_shm.c > @@ -222,6 +222,9 @@ struct tee_shm *tee_shm_register(struct > goto err; > } > =20 > + if (!access_ok((void __user *)addr, length)) > + return ERR_PTR(-EFAULT); > + > mutex_lock(&teedev->mutex); > shm->id =3D idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL); > mutex_unlock(&teedev->mutex); >=20 diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 6e662fb131d5..283fa50676a2 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -222,8 +222,10 @@ struct tee_shm *tee_shm_register(struct tee_context *c= tx, unsigned long addr, goto err; } =20 - if (!access_ok((void __user *)addr, length)) - return ERR_PTR(-EFAULT); + if (!access_ok((void __user *)addr, length)) { + ret =3D ERR_PTR(-EFAULT); + goto err; + } =20 mutex_lock(&teedev->mutex); shm->id =3D idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL); --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany --M9NhX3UHpAaciwkO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRPfPO7r0eAhk010v0w5/Bqldv68gUCYwNlYgAKCRAw5/Bqldv6 8rEvAJ4gSuJsaW+I7NP5zQXi+5g54XgV3wCfTKL8kfOnTwL1l/4nPoVVKLXS4vE= =wjAN -----END PGP SIGNATURE----- --M9NhX3UHpAaciwkO--