Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1237816rwb; Thu, 18 Aug 2022 23:09:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR51J3TqXPKEKHlenA6Sx1EwAbcKtexJx21f/o9QxXqox+CA6pjMyeN73Se+1BcDm8pLDvgc X-Received: by 2002:a17:90b:3b85:b0:1f4:f76a:d5f6 with SMTP id pc5-20020a17090b3b8500b001f4f76ad5f6mr12474165pjb.156.1660889383862; Thu, 18 Aug 2022 23:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660889383; cv=none; d=google.com; s=arc-20160816; b=pXVLCZ0QFRdNVI8+5l52y0Y9STcrebEPueCN/hwpkDyeH6dfWDnSlIl1RXA6KfgPt6 EbnG18ct+nGaV2/QXmbsyHbu8aVzoBDPKNLHOsyXPj+unk0tS/jmR4Shg1f0ozQaxa2q wWHFL8Cldyu4URNw3UGV/WZgiZQDzKTs40w4zLNeF81tFMfClsUkABjmbNzYAziHmiPl ciEJJfY2Q/SYEE3X79/vbJCULUPxcph4SIGkNvua4BqTI1zZvuCUdqUoaYQFu4Bb779F QmnCx8hYwWx61pNfn5dMZjheIvHhNB21I3wpt+1KTTrLjUDsaj95o5GDdrhbHLDMYiIs 8sOw== 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=HExoCPUxeh71DjLtXv6BaFguML8QWH5G+rMn+WNZF8s=; b=ngz64TM6M8H4onuh80JWwhReDeDhiPRp0Ury3JRcDlE5/dtWSK0FEa+nXoemu9Y92F owNkyjmHuf5NDyArVmEQpwdA6+6v1axUQepIKwRnurHYICvUxOaGZeUeYxwbzwWncbDZ s500Gup/DAu49rbnoYS/RoYJ9Bb+crCVUCQZUXxYxkIZ5uyLRzMXuPNYk2h0WhiDqY+h oBqm9Py85pNHpH17II9VtaUP4/MTVgMrpj31jCj90V3w7jFtrjeUGlHicsXYSsnAeBq0 SqZUYgjXPLWbZ00m2sN3Hp0xRM6YAbBxpBOGLNxjcGyiFPeed25E+xXishXT7fuF49Ej snIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uf7IL7ta; 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 81-20020a630254000000b0042a314550a1si1845902pgc.539.2022.08.18.23.09.33; Thu, 18 Aug 2022 23:09:43 -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=uf7IL7ta; 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 S1343720AbiHSGHu (ORCPT + 99 others); Fri, 19 Aug 2022 02:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245318AbiHSGHs (ORCPT ); Fri, 19 Aug 2022 02:07:48 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54445C6536 for ; Thu, 18 Aug 2022 23:07:46 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id x19so701579pfq.1 for ; Thu, 18 Aug 2022 23:07:46 -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=HExoCPUxeh71DjLtXv6BaFguML8QWH5G+rMn+WNZF8s=; b=uf7IL7taIuB9bjT2atDVlm1soO+RXrYV47lDW/AP0k+uBT+4kPKOZ3qFHn19nag8Uo bNeS/VJvsCplmpHmvjj8aJZtGb36788sLlWhwb6c6rmwmQ241e0CotKIY9+eLcIfmqAU kS/+CbpXq0iZvH+q/3aQmDFLuKKEXhHaUNcTAwjsPGazUsQ0r+rQmYWA7GDTLh5cnbhF QsxCkEp9HWe1+GDJt3osOjOyH6/dvoYiGsF25/R/baVVFSGG48gDe+NuHcOOHgytJ83S SJB490T/lrz9qJujXWVwnCDusFkER6WCW593k0XcsZZ8bp33VV5OyceeL95lkuXqJKMf Sysw== 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=HExoCPUxeh71DjLtXv6BaFguML8QWH5G+rMn+WNZF8s=; b=U4fUIzoK5fwntCu3X1qhSrJKHLInSdAGGFMwfr56dLeYmoYhiXhGqFUtXMZIYShstq 5AN/91oB1oHe+pbtIe3x17ofTc0Y3XQipa6tJsCp5azJLMFpf1tTwKkTXG9jeOY5inGl FQiKw1vTdHiYwqN/oO8tuj+dYQuzbMSEtex2lNWeQnqA68ilMBKv9WN1PcO6iKKlpDEg iDl3IzbXGKQpJ4Pq3OMUZ1NkEM/7MbXyQxnBbnc3J2VX7emmQf9iO2lV95z/fQ04uuBW 4sDnHgMJPun6acgn3Rr+/cWX/KPb1YpSIKaBclN31Y32HB9v2HnicwHhlEbz/mvkeHvt bpfQ== X-Gm-Message-State: ACgBeo35yDuuBMX9/fvdjI3GOP9OYxnpDRhOJrTELWb4mIuwXvUlTZa9 huSmWEvE4iKGaPsRdhRA8/bvgGJtvukBg1kFMsTyLA== X-Received: by 2002:a63:5809:0:b0:42a:3145:507d with SMTP id m9-20020a635809000000b0042a3145507dmr2727779pgb.428.1660889265831; Thu, 18 Aug 2022 23:07:45 -0700 (PDT) MIME-Version: 1.0 References: <20220818110859.1918035-1-jens.wiklander@linaro.org> In-Reply-To: From: Jens Wiklander Date: Fri, 19 Aug 2022 08:07:34 +0200 Message-ID: Subject: Re: [PATCH v2] tee: add overflow check in register_shm_helper() To: Linus Torvalds Cc: linux-arch , 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,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 Thu, Aug 18, 2022 at 6:38 PM Linus Torvalds wrote: > > 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. Thanks for the detailed clarifications. I'll remove the redundant overflow checks. Cheers, Jens > > Linus