Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2327875lqp; Sun, 24 Mar 2024 13:43:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWPRsakITY5YR0RRMI2O0dNBLWQ/2gC1a37JpqddryWQmhhl7LdQhU5kRdrJGyx0ftrFG5dO2/6hHtEmEQ6I6lejWe2UPtqPrMF+aIf5w== X-Google-Smtp-Source: AGHT+IFiCOyVyonH3ephQW68Kme77ToiO5iVaH6CGwX19O4BeZAXrWZi4Qf64Awh8Xbplc8qDoIL X-Received: by 2002:a50:cd4c:0:b0:56b:a565:f8dd with SMTP id d12-20020a50cd4c000000b0056ba565f8ddmr3510762edj.24.1711313016929; Sun, 24 Mar 2024 13:43:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711313016; cv=pass; d=google.com; s=arc-20160816; b=iBMDdHj8CYDBY2HTB/PybUeqLOj7tcvcrObif6LXlId/5NSUa5ntfILoyyWXsJBFQ5 hbyCeM6IoS2ckNFRNOiXVW0q/RL9nuU5Gy55EDsr/BfHI5WDvo+/ONHcXXDii6csHLhV 8X438NUzl730HEsw+cuvVABkSqMJ0nVobbREtUF2MAI2tooOeABehyasGxzE/TT6qaQd 1BcSzYpLbbaMbKfyW7b5+/lpZo1QJMCviwKfO53OjSQWxbveyuqWy3jK2uBg2h9hFsw+ veoTq8G6b48eI1ChioFeTlxqLxo9ZtJKnG86UrmomtnLSOEFPD4lVMjGVeb09nUtXov1 SPWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=tHiCJgwsQKJHisSLfnjluPrewQvoA1WkSLlpjUnXjuI=; fh=UpPiDKfXIuWcJgumW5XpTFdVE0ePzfAJmy93sNP1pdU=; b=EjOTsl81BH4q17sCOWbtLRV7jxlvX1XIogdu1F7f8bAIxErTb66LRccW5F52gaglrV tzOn6tw2oPk0A2WMytOmAKQQQcEAG7Hk8zgPHMtsWe47p0hT4Fo84Uvh5kSAHqaduBcL wHi4DQNT9kF/xiPNoqmKzsU1PNVVENyRsSMwoT9DWEKgEuI8rREVQ5QvTBSexqMwywxL EO17RLNghXP7eEqAm4bTEcq2NrajBwbQcMALR0l+3x1B3gttfVV40WqcAo1WPkTJGeir 39u0zNL4bEE+4Ddg8knod5n9AZVbJ33D8dvildhUx/j9EMgimCasI93KEd27bEb3NnlF adSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XDJ0xsgi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z7-20020aa7c647000000b0056bcec789bbsi1907915edr.642.2024.03.24.13.43.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 13:43:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XDJ0xsgi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8CE8D1F21154 for ; Sun, 24 Mar 2024 20:43:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E65F19BA2; Sun, 24 Mar 2024 20:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XDJ0xsgi" Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0158533EE; Sun, 24 Mar 2024 20:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711313001; cv=none; b=R/IBHrI/VhKZq+dV4jnxpO2Rx8zuRBwnSWq3foQPfUFZptbUDQmDMOkxn17jZFG/D/l16LanZNBpX3/+DWvLzQY3u3RpH25BjZRO8mgkych8fqFzMlnNK8ju+QGIZ5BQJ8l9IE24qalLcVzPVFQZzEatrrHCYhBAHOvyeOGcMRU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711313001; c=relaxed/simple; bh=BWpC5Sb75blq1j1DSHb+BAr/ABqvga9SnLzwpTWDWFU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Shj20MJaYo7s64SW66Y7AhlwIMwm4c9KTkUaoTYBtscNQazW/x5hUbESrXkVsm6idHkX3tpFEBzB410PjD2b6Xb9tcNSUbmnPPChcYOV2AakbA4IUcSMyE2q//RgpSTsBHBEJDmcUw70LY6F/N7cJNpwipS0f2yvuxEQro0jeQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XDJ0xsgi; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33edbc5932bso2648483f8f.3; Sun, 24 Mar 2024 13:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711312998; x=1711917798; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tHiCJgwsQKJHisSLfnjluPrewQvoA1WkSLlpjUnXjuI=; b=XDJ0xsgiI8AOcofSHtqtsCE5otWVjKmG/9aXCmPEE4u6UWK3KXt4CFmbB7pylujag3 /nBmNg28by+xvb7biAVogYa5T4ZlziHP6bwLnBJubjIu5hDLENaz2nZ2J55LlfyUda2J mgV4/F4sIBhEQKPnwdr0dIPO0DGMm20Kcgs5v80Gi4mB7M90K0yPhFcCNdhF7tCxRELi x0Y5vZ/ImURYI7iNRbXE8hoOkTbdTCaI8GeANJO4jMSLxt71XD/2zJhs2BWNiMRIltMi 7YSWE+dSwQJZ7EVXSJHdS77tYpErvHnrtnqYZANzkXoLbABJxBsWBZQhAZlK7BrB9HcI gupw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711312998; x=1711917798; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tHiCJgwsQKJHisSLfnjluPrewQvoA1WkSLlpjUnXjuI=; b=KNbzxr9EDmF7c7Ed9r8Hc/jybhFi5riafYL2DKq4SSkLWg+pB69Do8lZAI1ZEyxiS+ 5PU1wpZ2MLjqcC8kqTO+SNfxmicBZwMmAeYqqX1fw6DI4fGMumQkvCwf0RWge6UWycsB I7szsbE3B9t2mLP/iQZCqIZZucJQyrtjao+gy+Gt2WqyESUnXa9MganoGSHfHwbSolc4 vFuxJ3uPmYWUIu3qkkGxaBR3eaF+3LJOp/BWdXVE9mOhpKHFhhyCV5pkobFwYkAtz9tk SkHKNo361uyI4Wws6oOoMwWRW7IIfXFigWSsnz78KFEO/lenO+CXHx2CH/+ATBkdFZdC gP6w== X-Forwarded-Encrypted: i=1; AJvYcCW8c+LF2Zhl9Du90G0DMeR5EAVPHebab9ftgx1pdzZKQ+SDedUNrKhjno16rCiNqHk/tREiuSoWGwB4G6bmLMJU79nN39B9FQM0dkJJSh1oQQdPqiVeCZNxeQtmqko/ZfhuNrlD84/Lp7coU65ionEwJq4UP0STV5yC X-Gm-Message-State: AOJu0YxyMoCmBPeO0ytU4mWKJwXP3XN/9vjqXP96Er+XdU2WHqi3B9et xP50PLmyyuBzKhipRVH8Oi/xJh7PlM0SsQB3oSlL8i0qk9tacYa5nFMvMt01/KluAZ8ooql4YEt grzSm10LztB9eQaowR3Cke1hHSCo= X-Received: by 2002:a5d:69d0:0:b0:341:bf1e:45a5 with SMTP id s16-20020a5d69d0000000b00341bf1e45a5mr3460066wrw.46.1711312997972; Sun, 24 Mar 2024 13:43:17 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240320105436.4781-1-puranjay12@gmail.com> <1686adb401b34adaa3b703ec1a8ffe49@AcuMS.aculab.com> In-Reply-To: <1686adb401b34adaa3b703ec1a8ffe49@AcuMS.aculab.com> From: Alexei Starovoitov Date: Sun, 24 Mar 2024 13:43:06 -0700 Message-ID: Subject: Re: [PATCH bpf] bpf: verifier: prevent userspace memory access To: David Laight Cc: Puranjay Mohan , Ilya Leoshkevich , "David S. Miller" , David Ahern , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , Jean-Philippe Brucker , Network Development , bpf , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Mar 24, 2024 at 1:05=E2=80=AFPM David Laight wrote: > > From: Alexei Starovoitov > > Sent: 21 March 2024 06:08 > > > > On Wed, Mar 20, 2024 at 3:55=E2=80=AFAM Puranjay Mohan wrote: > > > > > > The JITs need to implement bpf_arch_uaddress_limit() to define where > > > the userspace addresses end for that architecture or TASK_SIZE is tak= en > > > as default. > > > > > > The implementation is as follows: > > > > > > REG_AX =3D SRC_REG > > > if(offset) > > > REG_AX +=3D offset; > > > REG_AX >>=3D 32; > > > if (REG_AX <=3D (uaddress_limit >> 32)) > > > DST_REG =3D 0; > > > else > > > DST_REG =3D *(size *)(SRC_REG + offset); > > > > The patch looks good, but it seems to be causing s390 CI failures. > > I'm confused by the need for this check (and, IIRC, some other bpf > code that does kernel copies that can fault - and return an error). > > I though that the entire point of bpf was that is sanitised and > verified everything to limit what the 'program' could do in order > to stop it overwriting (or even reading) kernel structures that > is wasn't supposed to access. > > So it just shouldn't have a address that might be (in any way) > invalid. bpf tracing progs can call bpf_probe_read_kernel() which can read any kernel memory. This is nothing but an inlined version of it. > The only possible address verify is access_ok() to ensure that > a uses address really is a user address. access_ok() considerations don't apply. We're not dealing with user memory access.