Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2482222lqp; Sun, 24 Mar 2024 22:51:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUttNVGY3TuyuaGEhQ2ND/fSk1era8cK3HKS7p8Dk2OuxZ+0TEuESNYKiMVaqDvaHzYHMViW/KDoE5uFMaF+IgnD2EO4Hu09CCN0xNmWQ== X-Google-Smtp-Source: AGHT+IHWbyRcY10VOw5aCxoSbXW6tZb9ZGuGMRDd23EPEvq1tP+xPPfekLELz5h9aVp7ISEycitI X-Received: by 2002:a05:6358:480d:b0:17f:1ceb:1d54 with SMTP id k13-20020a056358480d00b0017f1ceb1d54mr7066527rwn.10.1711345911338; Sun, 24 Mar 2024 22:51:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711345911; cv=pass; d=google.com; s=arc-20160816; b=yeajOih2PczDAHbsGnGsnCr1StMXyqrRHL7npNA0BzJvnqhZOe92s0F1zfGNJWZgGS BbIKtxlBH5+WkDgP1btVnCXHjZIBAkDwoNrqUL4SmgB7N6HsPkz23i5n6aTqUPRIn/u6 gxmIoLhcALdIFEi1Mm8zQSEC46AFzZESx4TmV6WF1/T8jXOOId1g6uMqt3wt4+pJ8kls amlNbgnGJf1k97T+IqYW+EPpSgaUr9EVJBVD0e/Kt+vBHRK3M2VtoplZ7uRkhQMNbkDq U8KGRlANQh/bC6vFw0kMtDj6a/13EimxkyLcz0565Rcb4XmpZg5p3j9BqLlPV4pERTrT 2EPA== 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=rymGosSZY4eZQBtQAJDoTYCW4+6dXqpQDiTevlfvmPE=; fh=RwJx/zoC2A8lPPb+lOGjcTIZmp9TVgRdYdp95AD6138=; b=jIJxrRN3QWKn5srcWQ7QMKxltk2ORLJfo7o2yuPwf7oEip90/OuVK7UJ+Q4AXUPjNW wDA43MIKHqsLOmyHbjxFHTpUND04974X+4shJTC7STmasC+RrChy30UhLJ0azLdhzLrM 8mSrYz4E3LeKtIJ+Cc1XN/viFQ3YQuGN0hDEDGaiVzdes7mhVqxraqu+vczMiZ0OPMUy OaGdJ0NC0r9hmWBn5HEghfk5mDMy8Qc3gzhJBLVDbCnVOKbMn0m3lhLMf5IcQePx1R8d 2ZdoxJ4QzFVIzbigDNnKuV0QbRsu20FncFRl9k8D8S0sUKCb/6dV27GWun8VU6Gi6xYL WTMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PmzpY9+l; 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-115125-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115125-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 65-20020a630244000000b005d849f5352csi6837162pgc.795.2024.03.24.22.51.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 22:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115125-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PmzpY9+l; 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-115125-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115125-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4D612B3308C for ; Mon, 25 Mar 2024 04:43:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DB052FEF80; Mon, 25 Mar 2024 01:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PmzpY9+l" Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 C67591826E1; Sun, 24 Mar 2024 23:49:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711324151; cv=none; b=e2y6V4c11tt/Q1WYynycVBHN84L/TMXF6w6pquca8L3UXgcBwVOb9xOd8I3/KsoxMhmVibSam9v1VyAed+1thzt1wUnbwZJvHBEw7FS/X0GF4Csy6yBG++BoKNmjlfBc3X3BvhOMWLrJfyfYXMUfPMTv3roh6+5rJ50cBmVMK9c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711324151; c=relaxed/simple; bh=LFsZTRHTodwxEEOWKO2+M2F3Tn2p02vzi+3C1Wgsjpk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=H+veooiko2pLB/CTedqoG/Je7tRy0Sl5UzxRxSRA/gLfAwIyczxIxhQ60gW1rECbHn3VhVHC5kdlr0jWt8ElkpP47W0bJrfREEUBNkjNk78bnB2jPP+HQOcWmBpEcrx/9YIVYH1Uc44eYAgilZ6Da3CkdUrGIdvgekw9CDqIpfw= 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=PmzpY9+l; arc=none smtp.client-ip=209.85.221.54 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-f54.google.com with SMTP id ffacd0b85a97d-3417a3151c5so2460058f8f.1; Sun, 24 Mar 2024 16:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711324147; x=1711928947; 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=rymGosSZY4eZQBtQAJDoTYCW4+6dXqpQDiTevlfvmPE=; b=PmzpY9+lzY57zYbpE3RrmQwlk9jXUZ46SX0/iiipIcI2l9pey164dplL5salIwW8vE glhl4/D/Z0GUBsWrla8TG/+T6u5bjUODSWvd7ybnkYDKVlrJJp2GsPwGhvdEy61d80uJ dQ6Ipr3nJAk9Lmfeeb40stERKtrE4KQFANzrqEV9HXJobteNCwtvdbzk2w34EWzbqxBC zgQXd8wJNOhIcsCYKNJXvAyxa0IZdgp+sBQbal2HeGwR6s0tJOJOSQ3Dp1ibTE5OUGDt dh3p8MCy6cgYm/kulPR0cc8O4CR+EimZFK0APVxZ1zwUQkjZO/CWuQQwMII3XTjBuMEf Ke/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711324147; x=1711928947; 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=rymGosSZY4eZQBtQAJDoTYCW4+6dXqpQDiTevlfvmPE=; b=NvpT6xvkvTcsbDc47gkfcnBx7iC0Ne4vuk81NkZAbd2X2xVrG66cPXkWSGrZ/S6FwG KwYT2Bgae3QKwJIaKWgwzGJsPQdRAvk3HrOByPv3bkFnCo9K8XZi+CyOSGOS64hT1WH6 +WjlsR0gzsvSrS36eIBGv14aSb5rcJUFjDdsDdktIqloYByixu/TCWFWvaaPuwOVP6I8 Y+deI45B+Xy/ZENbljvMloqm4qVGwdiJW1JoW2e0BKfzsquN6YnuN9qQh6eJuRSMk3R6 CAnDtwYyWLGsXCuRinR7qsOT7UcfQ16Kp37DNUf7pdfJFk7uR2sYo2aE+RQ6vVjBn4ny SSqg== X-Forwarded-Encrypted: i=1; AJvYcCXxb5jBDqJMseBl0+TeJo+Wt56LVTGrkdaFHrtcXEGzigX8DVyRB4HV49y7zR9R8RHoHgWSo1u1eGQWiCa2KtiyXp9MMbciM/uw2gVFFg7BBkH1FRd/XnkzHCHxFGQiWjpsdkJEonHWbdNybHE+udHLC0bqyc4FZvEf X-Gm-Message-State: AOJu0YzvgkEi6oAzUQRAIyV90Vxrx40Y/eqeXkhlt0j5XubKVQkvuIWa 8t3ZMxdQsgygfOfe/p+yYCs6+Lo8c4H9hWxsxYmI7+ryDe5XxEzQ7QVL0MnGRy4gxehnnTMS6Ne +qqAenFSS0b4xkkF1jBzB5BsgyjE= X-Received: by 2002:a5d:51d1:0:b0:33e:6cce:c2ea with SMTP id n17-20020a5d51d1000000b0033e6ccec2eamr4432251wrv.51.1711324146870; Sun, 24 Mar 2024 16:49:06 -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: From: Alexei Starovoitov Date: Sun, 24 Mar 2024 16:48:55 -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 3:30=E2=80=AFPM David Laight wrote: > > From: Alexei Starovoitov > > Sent: 24 March 2024 20:43 > > > > 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 wh= ere > > > > > the userspace addresses end for that architecture or TASK_SIZE is= taken > > > > > 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. > > It was the getsockopt() code were I saw the copy_nocheck() calls. > Those have to be broken. No. If you mean csum_partial_copy_nocheck() then they're fine. > Although the way some of the options use the ptr:len supplied by > the application you stand no chance of do an in-kernel call > without a proper buffer descriptor argument (with separate optlen > and bufferlen fields.) > > > > > > 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. > > If you do need a check for 'not a user address' don't you want to just > require access_ok() fail? > That would be architecture independent. No. access_ok() can only be used on the user addr. access_ok() =3D=3D false on the kernel addr doesn't mean that it's a kernel addr.