Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7063346rwp; Tue, 18 Jul 2023 09:28:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFKgtVpVex6pQV++QII9MOVb0g55kuuQzcAPKJ1hMwFQRBFTejJYpXVlg0Hvy6BlGPG/n2i X-Received: by 2002:aa7:80d8:0:b0:682:59aa:178d with SMTP id a24-20020aa780d8000000b0068259aa178dmr12352740pfn.1.1689697709167; Tue, 18 Jul 2023 09:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689697709; cv=none; d=google.com; s=arc-20160816; b=P9DKsLO0BdOe3l5Nk3UsmsEbakC/qY6dQ3STzti9MGFaL9zykcBD/kZhS2UUz5JRPq KlIWQGEbM24QBJnyYU78teSczybgACPdbtDdPMpTcikq4wgDRoKNu+/8QIMUOENgudR2 kVOCZvJKEvQFQ0xKZ9FsHo2PuodSeaQaDDgFkcRaKYw/8vvc4AG3LtAkhO11d7ZuPI+9 yzk7QwDPjJFcZS7lFTSad0SUhrYFD8iGnkxiQfxmlamQXWq9bSgOMiiATgk+2AdPsKv+ ubuT2BT4kDA3OJ0Ias6bombY+rbY/y/5dlAhx7mvA5yG3Uxqai3esWWYdt7yHpbNOAE1 VQ/g== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=d3zc66YmxMFr9XZAcgO7u7h9bwB0y90msq3fgQljzGA=; fh=p4VmqjMceWI3/eUm5U6fvhE8E3aaa4Bq6UDT/AHBGZQ=; b=YkHka8yXSf3nPwCnuJZFGv4SVYcmM0ngxQelPL94phMSIHVK8BoLQXLxxtYTauZTvr k79tAXMfuThxGWGRsd5C9vtdjSZjlaTpcyhMFAH+JbEwfOuhvSWXrBunWzGK/p0uZ82Z zzdReS7IuFMqiDobXb1ituxsT5N8Vap3DBzf8S2CfSXPG6ybBmki+0tXR2iq8K4c7Ote 1vdREEjy3hE/fK4OuEHg9sUfs6YQOVqABQWHh4qlUvy43qNqWGxgye6Y7IzJvBHx+A07 P5pIkR/lhlluZenxbohBa+Zc0QgBVTgV0UaVSQBF+h0FWjHce0cye8Y++IzF+5P2tjKv WFpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qIb3AHg2; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a633303000000b0053ef158b0c3si1752867pgz.25.2023.07.18.09.28.15; Tue, 18 Jul 2023 09:28:29 -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=@kernel.org header.s=k20201202 header.b=qIb3AHg2; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbjGRQGg (ORCPT + 99 others); Tue, 18 Jul 2023 12:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbjGRQGf (ORCPT ); Tue, 18 Jul 2023 12:06:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF36F1AC; Tue, 18 Jul 2023 09:06:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7A3EA6165D; Tue, 18 Jul 2023 16:06:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B576C433C7; Tue, 18 Jul 2023 16:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689696393; bh=EOkdjFMWH7brfMl6FFZE0qz5Gq2zAqO7jP+yRL3OVlU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qIb3AHg2MbxQcaCcnDObe7IyWQP9EULqWkf332wERinXUyRdCHH/qCNeIigrp5Ycw ydaIfRizs/INJy0ZXVU/+UZxqXbZ1IndtS1QbbNupQjXFCMOZ7s9GtI5Lx1NiLYhed N/TXvdwYWv4fstA72glvLH0cz5taXu9s65LrpLU7ltohhuRGO22kZCO1NSDiaci9Yc TJl7yenY0O0Vr33FHbShSyg4HHSBhu5lDXZoQp2aT3kvY61gJajckRsCIyRPO8GqYb 736uydTpvyC9e+RNDJoH0F4C0bAE+h387TX3d2LR2rVDoFVrDCpdJmKatD4hvVsZ17 nWLnw8l6c1maQ== Date: Tue, 18 Jul 2023 09:06:32 -0700 From: Jakub Kicinski To: Alexei Starovoitov Cc: Daniel Rosenberg , bpf , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , LKML , "open list:KERNEL SELFTEST FRAMEWORK" , Android Kernel Team Subject: Re: [PATCH v2 1/3] bpf: Allow NULL buffers in bpf_dynptr_slice(_rw) Message-ID: <20230718090632.4590bae3@kernel.org> In-Reply-To: References: <20230502005218.3627530-1-drosen@google.com> <20230718082615.08448806@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 On Tue, 18 Jul 2023 08:52:55 -0700 Alexei Starovoitov wrote: > On Tue, Jul 18, 2023 at 8:26=E2=80=AFAM Jakub Kicinski = wrote: > > On Mon, 1 May 2023 17:52:16 -0700 Daniel Rosenberg wrote: =20 > > > --- a/include/linux/skbuff.h > > > +++ b/include/linux/skbuff.h > > > @@ -4033,7 +4033,7 @@ __skb_header_pointer(const struct sk_buff *skb,= int offset, int len, > > > if (likely(hlen - offset >=3D len)) > > > return (void *)data + offset; > > > > > > - if (!skb || unlikely(skb_copy_bits(skb, offset, buffer, len) < = 0)) > > > + if (!skb || !buffer || unlikely(skb_copy_bits(skb, offset, buff= er, len) < 0)) > > > return NULL; =20 > > > > First off - please make sure you CC netdev on changes to networking! > > > > Please do not add stupid error checks to core code for BPF safety. > > Wrap the call if you can't guarantee that value is sane, this is > > a very bad precedent. =20 >=20 > This is NOT for safety. You misread the code. Doesn't matter, safety or optionality. skb_header_pointer() is used=20 on the fast paths of the networking stack, adding heavy handed input validation to it is not okay. No sane code should be passing NULL buffer to skb_header_pointer(). Please move the NULL check to the BPF code so the rest of the networking stack does not have to pay the cost. This should be common sense. If one caller is doing something.. "special" the extra code should live in the caller, not the callee. That's basic code hygiene.