Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1361233rwi; Thu, 3 Nov 2022 04:32:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6m8tJqGPtl1js7gvUKEZHtoPzbyPBIrwOJBm30rBuHg7ydMw/d0zKXS1WPXRXWC+ciKIH5 X-Received: by 2002:a17:907:9705:b0:7ad:b14f:d89e with SMTP id jg5-20020a170907970500b007adb14fd89emr27235104ejc.745.1667475147852; Thu, 03 Nov 2022 04:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667475147; cv=none; d=google.com; s=arc-20160816; b=K7ajp8EcfHECefvxfMtTwVIX1MVNbHptupxG6Xhzzh90XXlsB6ET6Ygg/p0IAuDI9c Q14d9UUmjh6ht/fMG3Ro1C873waFzi1Et5aVn7UIGNSfhiPV+c6WcW90u+CBLGjU2v1p e6z5gPcPTsDTyxHoAgGcy4sGqSZl4MdR/9irCNE0HrBdkxTm2NvMYlHDoWXf33YqHigO tQEMrCajziR8SRSoGI4Qj+Ha/kPXuqM0g8vFoAzev5uvVHflZ/xcRyZJYGI++1wo8731 eKzuXR+/tkhWPBdk4lAsS91UQVOZ9zO9HonmIYLRpo10Ny9c2QSVdvCacbEM9XxSDNJd PALw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=FhILi2yfvcxktek07eALVO1HW7rm9P9MDUCD3dvjgj4=; b=eI2+8rmKwshMtxcgh27skktV7aNS2qAsEL0uK5BtJGJEZRWRFXNzf47NOKbS0CQ8Kk 2qH3vNF2MJJzw7DcDEIxwgB6GoUpcR2sv4eYqyBCbch7PAKWslm7Wp5rQ5cxB+h8EYUE HPet5V1o7IvqvbvYx738LBF0daFM4plp/FfHMtLSBveBBYjzRRBMJkNQ7oM55wBBBvBo dgLMf9/OIOHgeaLcucqMZ2Fqr1Odh/T4nVeJdL6NZk0u74SKfzn7kWnu+GzxyWy59wQs 0v/f3KO6mmQ1KhSLtLRD5d08nRu3pICvM3uFsERif3u+SxMa3zpTNQOwtHrSMyKTMLBc kMJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=uEwHMbZ4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn41-20020a1709070d2900b007adef1e3ba7si1016090ejc.587.2022.11.03.04.32.02; Thu, 03 Nov 2022 04:32:27 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=uEwHMbZ4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230315AbiKCLXy (ORCPT + 97 others); Thu, 3 Nov 2022 07:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbiKCLXv (ORCPT ); Thu, 3 Nov 2022 07:23:51 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07EE910FD0; Thu, 3 Nov 2022 04:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=FhILi2yfvcxktek07eALVO1HW7rm9P9MDUCD3dvjgj4=; b=uEwHMbZ4rD8zck0Mz0UGcuvEQ0 y3D4aZVJrWTJL8/ieTRoUZ4LAYaO1SXm006oXFwKxXYC7rtchdOAeT0zejdtPc3rMGT7Zxr06VhQh dnfHxX/4PkT5a9SykYNegtnQNMkRp5HzYq39vwkWYx9QnaTSNia7Qadskbjk3jYNwMnTjx1oi2LUD vJDnphR7tjTZSpyHGZUcKl4PycinJt45wGcTM3UDC+FcEtm9Cc1jj+EALteqyfKG7kjV8AjBLtziS wSIUcAm+dhJSAn3nA5a+ZegNJ87y9f1la1F6OMnc7wZwpSlzdhAm1V2j491M5JcqEnQFwawcZG1Xc gWfnG6oA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:35090) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oqYJX-0006E1-8A; Thu, 03 Nov 2022 11:23:15 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1oqYJR-0008Jt-0G; Thu, 03 Nov 2022 11:23:09 +0000 Date: Thu, 3 Nov 2022 11:23:08 +0000 From: "Russell King (Oracle)" To: Yang Jihong Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, illusionist.neo@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, benjamin.tissoires@redhat.com, memxor@gmail.com, delyank@fb.com, asavkov@redhat.com, bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH bpf RESEND 2/4] bpf: Remove size check for sk in bpf_skb_is_valid_access for 32-bit architecture Message-ID: References: <20221103092118.248600-1-yangjihong1@huawei.com> <20221103092118.248600-3-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221103092118.248600-3-yangjihong1@huawei.com> Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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, Nov 03, 2022 at 05:21:16PM +0800, Yang Jihong wrote: > The error code -EACCES is returned when bpf prog is tested in 32-bit environment, > This is because bpf_object__relocate modifies the instruction to change memory > size to 4 bytes, as shown in the following messages: > > libbpf: prog 'kfunc_call_test1': relo #2: matching candidate #0 [18342] struct __sk_buff.sk (0:30:0 @ offset 168) > libbpf: prog 'kfunc_call_test1': relo #2: patched insn #1 (LDX/ST/STX) off 168 -> 168 > libbpf: prog 'kfunc_call_test1': relo #2: patched insn #1 (LDX/ST/STX) mem_sz 8 -> 4 > > As a result, the bpf_skb_is_valid_access check fails. For 32-bit architecture, > unnecessary checks need to be deleted. Isn't the purpose of this check to ensure that the entire pointer is written, and BPF can't write half of it? > case offsetof(struct __sk_buff, sk): > - if (type == BPF_WRITE || size != sizeof(__u64)) > - return false; Wouldn't "(size != sizeof(struct bpf_sock *) && size != sizeof(__u64))" be more appropriate here, so 32-bit can only write the 32-bit pointer or the full 64-bit value, and 64-bit can only write the 64-bit pointer? Or is there a reason not to? bpf folk? -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!