Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864785rwb; Fri, 19 Aug 2022 10:39:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tQ7QcDmx426zkzAPXnrut3CC9X3P6nsJq9qKD85utrT+O64gmCf8VGSQY0KzvkibCZ2u8 X-Received: by 2002:a17:90b:4a0d:b0:1fa:c277:126e with SMTP id kk13-20020a17090b4a0d00b001fac277126emr11867969pjb.246.1660930792406; Fri, 19 Aug 2022 10:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930792; cv=none; d=google.com; s=arc-20160816; b=bvmGWlsfONYrhnN2Nqz8bh2mMn7+LdWGhp1yaBNUxx+QeJkViFpEEbq+Y9S3iBfp0u tq46+YYyTI0YnYMQyr34rlddlknf9Zf7rkw3FjmDfeVyg0v5X/PvrFG76NtfMgY2ZKC/ 2mTF0J2A3iSSFWg3idNEKbJKeu+Dm15lY08yq2YYlzB90/KzTAd3bo3Ge4vTTE2biyjx hnodzqC9nU4pM69Y+Z9aiXvpwRDY1s3KAirJzwWQcatPFYZbA7XOIaBIyG9LhLG6x+/V jWy+cMZVHnxRVMqmnmurVgfRRSOy3LSmEFyBrF8uPemcfzVpfYFpwoZ+ogWwgLRiqzFw tmPQ== 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=MJi1SbEsV1RT6o5e2jrsKvHrDZ550g6YKkhJnupboGE=; b=yyu/4rClr0g0BVgkMKr7vJR/Rj6f8uVN+qBvI8gRaxGYVVOMhJxpHnjsoJAXYYlzJi Nmovc/HA6wHQGfUmbwBtigtwT3Bl16WWCZbFnO5Rk7EVSAWuBibDaPeDkRz6ddd4XEG7 9fsa+gkybX7IK05lHUffCHYu3peCv3zrqEVPicMAFc8iZP/UlOVYsRExXeQqYdNf1vWK 79eJ8YWC9KJoIPQ5g4tFSU+k9ZNXFdkuCE7BJEzaaKF/uJGfFco4PnAd/mlSW+SgNqXy /iHca3fQE/tGJ3NJ5VKW3/ATe4Bkno1KWyYpKn6/DiFJdKdGafD2cPdLq3USv0XGWZ1b Mwjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KyUglHcQ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj15-20020a056a02018f00b00410702fefc2si4643552pgb.390.2022.08.19.10.39.41; Fri, 19 Aug 2022 10:39:52 -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=KyUglHcQ; 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 S1349988AbiHSPm3 (ORCPT + 99 others); Fri, 19 Aug 2022 11:42:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349981AbiHSPlt (ORCPT ); Fri, 19 Aug 2022 11:41:49 -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 EAAFFEA336; Fri, 19 Aug 2022 08:41:07 -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 262D8B82814; Fri, 19 Aug 2022 15:41:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EE08C433C1; Fri, 19 Aug 2022 15:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660923664; bh=qh/axndb7wUJZpXguucKoIulVp/Qb3Nd7Atm6YWpB5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KyUglHcQebGDrtrwLWNu1M4ir0TS5OALsmqOMY7HEjtejt2cb6sMFLjxduKsyugpv DbJqbOMTUQcWoe3cDCAUFVGImrQPocItkbBU107NqAbvSvTmJ4tuRgrxZWLTknBqyx MF4+Xo6eb1esJQQgtJiLJh4GqqRDmxqbIBWpK08s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nimish Mishra , Anirban Chakraborty , Debdeep Mukhopadhyay , Jerome Forissier , Jens Wiklander , Linus Torvalds Subject: [PATCH 5.15 02/14] tee: add overflow check in register_shm_helper() Date: Fri, 19 Aug 2022 17:40:18 +0200 Message-Id: <20220819153711.747538439@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153711.658766010@linuxfoundation.org> References: <20220819153711.658766010@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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,T_SCC_BODY_TEXT_LINE 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: 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: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 Modules linked in: CPU: 1 PID: 173 Comm: optee_example_a Not tainted 5.19.0 #11 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 pc : internal_get_user_pages_fast+0x474/0xa80 Call trace: internal_get_user_pages_fast+0x474/0xa80 pin_user_pages_fast+0x24/0x4c register_shm_helper+0x194/0x330 tee_shm_register_user_buf+0x78/0x120 tee_ioctl+0xd0/0x11a0 __arm64_sys_ioctl+0xa8/0xec invoke_syscall+0x48/0x114 Fix this by adding an an explicit call to access_ok() in tee_shm_register_user_buf() to catch an invalid user space address early. Fixes: 033ddf12bcf5 ("tee: add register user memory") Cc: stable@vger.kernel.org Reported-by: Nimish Mishra Reported-by: Anirban Chakraborty Reported-by: Debdeep Mukhopadhyay Suggested-by: Jerome Forissier Signed-off-by: Jens Wiklander Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/tee/tee_shm.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/tee/tee_shm.c +++ 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);