Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp668014rwb; Thu, 18 Aug 2022 10:03:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR57wfFL0nCO4IhGERCiz3XKCw1kX5L/VvQzYqSknnDrF1mAQsrm3k39h1hNtZpdPLAI67sy X-Received: by 2002:a17:903:1209:b0:16c:ece7:f68b with SMTP id l9-20020a170903120900b0016cece7f68bmr3437190plh.112.1660842228859; Thu, 18 Aug 2022 10:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660842228; cv=none; d=google.com; s=arc-20160816; b=c7Dq25lEP+HvhQijMvQXdh0ubpZk424Hk6sss/w0lZBb3cf4DdskGlyj8zyrz1+GNk RTyGKMgvQ3FLbYhTMHdW4aBCxuUF9uzAMTjy737s9xdhsAI4SPgKoK0TliRL6cGu6emd hzbEug1vJqxtp7x1HrQueIJU/+A6RJDXsFfY2RbZsti7gp6uH7CrPK+uYW8mI2Qk6wn2 FSqsbEWiBrr//Wjg4+ZTwyErJE966+aK/vVaOzhXzPk5C2dDEIbp7SdHc6VRL4lIQOrF 6KcbdNeJCjK6U8ef9r2go3FtfZqm1AGSV+bewNdQ2weMHQPBYIaPPvIK1e3M1HxYyBAf exPg== 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=2B8tvc8B2hGOQWJ0UIEwuS9k9Pi3iffbpMUFMt6cRTA=; b=aJbmL4TsdoP+XWFWdqc7AKdYRX/69gbn5NLvnqK4DPRX6obq2vM3Dt9w9GQGYqIDQx YJw1TfOFAQ20rmPq5OZeQwl2pQ9xMDd48NymmfpRqiruAvCnjXtHeCGICcah3Q7tjdI0 3w2MybzyzGyQpB+ChLfoYWjsU23QL6cx1XQ3SUPOBNmLktocJmkjuaCbyeczofvSudK6 7Iv50DE58eHvwS/q3xJur/wWWY8lI9VxJ1PdJVptlGFRAaeec34QapK4hQwJBbj/iLVy uWLiLVDc77bCHoZioGV27lJu2q+iLzZYTbYHC2Tmbir0vSeUTA6cMiAaQh0qKy+YB0WO bFdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=ErGEvsdD; 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 x19-20020a63f713000000b0040dea781c31si1815913pgh.319.2022.08.18.10.03.36; Thu, 18 Aug 2022 10:03:48 -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=google header.b=ErGEvsdD; 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 S1344405AbiHRQih (ORCPT + 99 others); Thu, 18 Aug 2022 12:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239763AbiHRQif (ORCPT ); Thu, 18 Aug 2022 12:38:35 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CBD491C4 for ; Thu, 18 Aug 2022 09:38:34 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id c39so2612299edf.0 for ; Thu, 18 Aug 2022 09:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=2B8tvc8B2hGOQWJ0UIEwuS9k9Pi3iffbpMUFMt6cRTA=; b=ErGEvsdDtIIHCcxD24M8zXwYEB9SpeIIeJzzWl1gJpkkCmePawUmhzzEyHMxG94Ate GsURqbvPPl0c5qKNQiCNovk95SuLeVZazP7OmbqjwmpgPnpySNqwHgPlhjlPT1ccG1Bu Fns8MY8lhCRWCcYo8V/9qKS67ZVgGzkhMkhOg= 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=2B8tvc8B2hGOQWJ0UIEwuS9k9Pi3iffbpMUFMt6cRTA=; b=OEfWgeQ9YhYgpMBngbRal8J+4af1+cnbZ8F7gpABz0xijxJa8AOL86MC8LpkcIZAre L3dsCBFzejlZtIypTxlAEIMnVe56VaIg4dmz3j8jO0P74PTgKUzOwOg7wV4D7RBx8HkP YfKL8XZZwBLFlZ9naD/q7msJjOZnqsPLE3qZfBOpMpaqTviES2cCEarOgrgcFfzpGtPx 1HY2dH/gL9aO1/fuu2r8NfDZlMGPFdjpInaHfZVey83L9dfVlJw+Dlag+rsXEz+y2fjP t6O0+BpQZ/9K0mbw3gcOEatkcY9rLviBTMi/DILseUAkF5LqFDW75ZdI+Shwki8GYn01 PnXQ== X-Gm-Message-State: ACgBeo3/cuqBQC9d1y+lErljqHMcUZvKLbMaeqX6OkfxAPtAqwIebgAG g4SXh5cJ2pzJhWvebdse/jlzmE1IruhGV8Iy X-Received: by 2002:a05:6402:1e8a:b0:43e:93ab:5ab8 with SMTP id f10-20020a0564021e8a00b0043e93ab5ab8mr2889777edf.211.1660840712427; Thu, 18 Aug 2022 09:38:32 -0700 (PDT) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com. [209.85.128.49]) by smtp.gmail.com with ESMTPSA id ck30-20020a0564021c1e00b00445d760fc69sm1444027edb.50.2022.08.18.09.38.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Aug 2022 09:38:31 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id m10-20020a05600c3b0a00b003a603fc3f81so1246781wms.0 for ; Thu, 18 Aug 2022 09:38:30 -0700 (PDT) X-Received: by 2002:a05:600c:2195:b0:3a6:b3c:c100 with SMTP id e21-20020a05600c219500b003a60b3cc100mr2371564wme.8.1660840710358; Thu, 18 Aug 2022 09:38:30 -0700 (PDT) MIME-Version: 1.0 References: <20220818110859.1918035-1-jens.wiklander@linaro.org> In-Reply-To: <20220818110859.1918035-1-jens.wiklander@linaro.org> From: Linus Torvalds Date: Thu, 18 Aug 2022 09:38:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] tee: add overflow check in register_shm_helper() To: Jens Wiklander , linux-arch Cc: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, Sumit Garg , stable@vger.kernel.org, Nimish Mishra , Anirban Chakraborty , Debdeep Mukhopadhyay , Jerome Forissier Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Thu, Aug 18, 2022 at 4:09 AM Jens Wiklander wrote: > > Fix this by adding an overflow check when calculating the end of the > memory range. Also add an explicit call to access_ok() in > tee_shm_register_user_buf() to catch an invalid user space address > early. I applied the access_ok() part of this which was clearly missing. The check_add_overflow() should be pointless with that. And the "roundup() overflows" check should just check for a zero result - if it is actually needed. Which I don't think it is on any relevant platform (the TEE subsystem only works on arm and x86). I do think it might be worth discussing whether ALTERNATE_USER_ADDRESS_SPACE (and no-MMU) architectures should still have access_ok() check that it doesn't actually wrap around in the address space, so I've added linux-arch here. That's m68k, PA-RISC, S390 and sparc. In fact, I wonder if some or all of those might want to have the TASK_SIZE limit anyway - they may have a separate user address space, but several ones have some limits even then, and probably should have access_ok() check them rather than depend on the hardware then giving page fault. For example, sparc32 has a user address space, but defines TASK_SIZE to 0xF0000000. m68k has several different case. parisc also has an actual limit. And s390 uses #define TASK_SIZE_MAX (-PAGE_SIZE) which is a good value and leaves a guard page at the top. So I think the "roundup overflows" would probably be best fixed by just admitting that every architecture in practice has a TASK_SIZE_MAX anyway, and we should just make access_ok() check it. Linus