Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2345173rwa; Mon, 22 Aug 2022 06:22:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR53/BwVq3LQCTKpyFsy2Lw1LNuvNRHPBlgaKoEISz+JOD2MdX9UeZnmYlm7pKpQvtqjcbmx X-Received: by 2002:a17:90a:414f:b0:1fb:29d9:7989 with SMTP id m15-20020a17090a414f00b001fb29d97989mr6214809pjg.70.1661174555938; Mon, 22 Aug 2022 06:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661174555; cv=none; d=google.com; s=arc-20160816; b=obvSY6zk68cgC3Vz+V8DP2F/NMc9m9x74q7iw6tuz1GWk493IVTL3kzgaHvIVwz11o egU1cU7OUA3mRcZ9RoZZ+ovbkHMCMb3GjsAPEy732eLou0nM+N+k75xsj0AvqWfFJZUG ZN+C/lqCDfQo4DEAEXGQhzh1s3a2dB7olRDWT0hhAgG/qt7P/8Iu7mD+KYBCoOWj4Prn 1x+Iq0+LF1QAX0dtkCSu68CFc/wwzeu4nE8yHOujpAlJQ0dAvcI8sB/nPNQ4LqZsB6f6 7rfLv0lt5GvUv3ms2iWqIr/8UuLCdl+aEsVaOSfhBGjS0B9ZkajwemkQAJarMX34eQIO fTlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KENEwPWg+QM6i8lJVSpcOJR02BGDL6vvXXWnVkrSkKM=; b=M3onSxXGQSo2rHPF16ElhmiVcuqWbRze7V8XFpULsQOzizZ495GfI9hTvUa4wD9prM t0lhqlIPZ+phoeTK122pKdtEl5iVwf1WwA7L2wZdthaQbnc70Ze9wK6lfplzkD56he1e QdC91z9uNJ4ZOy2kxHqZQQWbX+FvknpYYvMVG1rBWUAohB5pNI00zxK6uGrbO3WDtJXA TCSSuep3G7OdPIajCbFLxGahumYbvBBti9LLK9F3jd40ZAluCd8XSw2azv9lN8W3MP/k C/sNM0eq81iMOYkgVL5mVLDcyWJzrF4gxk609NzF9MfYg6ocaEfM0POzud6YeBMQURGL GRBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m2iL2AOm; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a636c06000000b0042a020bd06bsi10190804pgc.781.2022.08.22.06.22.23; Mon, 22 Aug 2022 06:22:35 -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=@linaro.org header.s=google header.b=m2iL2AOm; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234987AbiHVNII (ORCPT + 99 others); Mon, 22 Aug 2022 09:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234670AbiHVNIF (ORCPT ); Mon, 22 Aug 2022 09:08:05 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AEDC2FFF8 for ; Mon, 22 Aug 2022 06:08:03 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id e19so9707525pju.1 for ; Mon, 22 Aug 2022 06:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=KENEwPWg+QM6i8lJVSpcOJR02BGDL6vvXXWnVkrSkKM=; b=m2iL2AOmlxu5RzDNkMGd8DaJOgjWBtIfddWC/0ETz+lOO9bjP/lJeTOhukYZEBxj7+ B0F2Pey8oqC0UacfNG8U18X2Qe2LuL9qG597GgjcOd6d1oKhR7nGTX0df99FBdV27bu2 LxbXEoBR0uYJGBacdOZ2Z8DAo/W8fZupquGIgHREBFArbKHwsQqdj6DzvvDkkOHDTHc0 Ln0tkZb1odIUZspG9CxgVmGicz7PHXrrztQQaErGGAzJ3T5/b9/JdIiM5o+qUA5MqqVL md3jcqlEKLtIT0sxbe8BEBiEZkdHPEPF6VWylXHlDgKmqkFH1yLC7QzIu3Rq/Yh0tC6d SBDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=KENEwPWg+QM6i8lJVSpcOJR02BGDL6vvXXWnVkrSkKM=; b=ugT7QHgqPis5AwLSWLFcOD416OvlL3IfCGuBo41SIv7lmMprgejac6L8u5dNDvOoR0 EN9AF02lw+gbCBBg00X6Eqad922w+gRVkQw2HoT7ZZ8TMtr+MGw5zliX7fsuad/1zYWL 2oUot8X9CTZ2nxkkJM+DaOWjcbT1ZfZAxHT2yO/96BZs2XARZb6abDhEcfFB4wkvO6jQ +FfPzAyIE0XcmQfwvtSsC9yMUZTt8NRI8FtwKc9qkI3KB3y5Nv6Z4/LHJA+FxAJjhRP6 D7PDwAXGI5R4CwKzhk7a4zWhaHLwYAvO+ZcWBME8Jn5jz6fpN0eVXDwqAtdfZ0uMn+k2 DjCw== X-Gm-Message-State: ACgBeo2QAI4/j0PhADG8jVnP28qUs3nC2jjUpOjhVDoewTkEn4um1wsM VWIjfjg/nGwrhNg+l7RlaNlGgAcp/lKWEPHK5iv1SA== X-Received: by 2002:a17:902:c411:b0:170:91ff:884b with SMTP id k17-20020a170902c41100b0017091ff884bmr20213120plk.58.1661173682451; Mon, 22 Aug 2022 06:08:02 -0700 (PDT) MIME-Version: 1.0 References: <20220819153829.135562864@linuxfoundation.org> <20220819153853.762825860@linuxfoundation.org> <20220822111546.GA7795@duo.ucw.cz> In-Reply-To: From: Jens Wiklander Date: Mon, 22 Aug 2022 15:07:51 +0200 Message-ID: Subject: Re: [PATCH 5.10 540/545] tee: add overflow check in register_shm_helper() To: Pavel Machek Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Nimish Mishra , Anirban Chakraborty , Debdeep Mukhopadhyay , Jerome Forissier , Linus Torvalds Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Mon, Aug 22, 2022 at 3:03 PM Jens Wiklander wrote: > > Hi, > > On Mon, Aug 22, 2022 at 1:15 PM Pavel Machek wrote: > > > > Hi! > > > > > From: Jens Wiklander > > > > > > commit 573ae4f13f630d6660008f1974c0a8a29c30e18a upstream. > > > > > > 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. > > > > > > 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. > > Thanks for bringing this up. I believe the best option is to take the > backport I just did for 5.4, it should apply cleanly on the 5.10 > stable kernel too. > > Greg, can you cherry-pick the 5.4 backport patch, or would you rather > have an explicit backport for this stable kernel? I'm sorry, I'm confused by all the backports. I haven't posted the 5.4 yet, I've only just tested it. I'll tag that backport patch for 5.10 stable too. Thanks, Jens > > Cheers, > Jens > > > > > 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; > > > } > > > > > > + if (!access_ok((void __user *)addr, length)) > > > + return ERR_PTR(-EFAULT); > > > + > > > mutex_lock(&teedev->mutex); > > > shm->id = idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL); > > > mutex_unlock(&teedev->mutex); > > > > > > > > > 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 *ctx, unsigned long addr, > > goto err; > > } > > > > - if (!access_ok((void __user *)addr, length)) > > - return ERR_PTR(-EFAULT); > > + if (!access_ok((void __user *)addr, length)) { > > + ret = ERR_PTR(-EFAULT); > > + goto err; > > + } > > > > mutex_lock(&teedev->mutex); > > shm->id = idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL); > > > > -- > > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany