Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7879910rwb; Tue, 6 Dec 2022 11:00:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EeI8rmtDHaVN4hrYUjKJAiG7fpItikpvlDp0YrlFUvU0AVcVX++QSwbiDb85vsNaBvRKK X-Received: by 2002:a17:907:774e:b0:7ae:39b4:7208 with SMTP id kx14-20020a170907774e00b007ae39b47208mr8840145ejc.766.1670353245626; Tue, 06 Dec 2022 11:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670353245; cv=none; d=google.com; s=arc-20160816; b=Gdz2+qz0SB9eJrQQaCUNX76KaBjc6KpkNOFmM63aZHU/NThBblLHi/5JrmboSeY/cx fEmvZXCIKBvn9+5cFa68NWIGbhj44ls4MYNvdQODXJkx7Y7t4AYedio2NisShnUJ1MmA 5Vd3jLM9SdZMOwEwcGzyDuJ5pWw0Wa8vpvh3+13adqhdBr+QymODaD20F9fbYPqAvY35 Ytw5OogCT1utj3HRRp6+XwaoylBQ+vyUk9wuQrNwUNncAzP0lgaiABwkjLJwzgMxVXmF MYeC6VxnkBfHDJ+VRUhLQYw/72ify5DbyJJJ9+VyqNKHCJUPKu5plz0hDbFxuc2dG58B 9X1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=vVTQ+Ap4e/KZs2xYUNBsyqF85aC6jCpJzIZ0LtrQ85k=; b=adkm4f2tEWRgjurWA9NQuwCedYdtjEaS0zfQyYrc4CRuC4nUGxfnRRcuAoNm5U4FWf Pokg75sT4UehBqrkPtsDEa7y7lWJO0pG1DlUrdGNyFRCP57Ji7iRxrqdCipIO6pJn5mw zQO3fxzogQdBv91VSRplfcH1m6EXOz5Xno0j9Z1YUnmlPjJ0uRwcChVIdaA2GE8nDmpn CRgsSITnANAlULYlUZT07cQTILpmQ3RiN54HlFuWjR5w/z9B2UG/O2Xo4R1EBKS5ID6H giI5iSEgEOX8DlsRom94dqYnX+D5xH/ZSVcMdrY+fBT6D3cY7smRrFdGfyrqekq9lqz1 9M4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=glcRjbZt; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd12-20020a1709076e0c00b007bddb7980f9si15467159ejc.100.2022.12.06.11.00.27; Tue, 06 Dec 2022 11:00:45 -0800 (PST) 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=@linux.dev header.s=key1 header.b=glcRjbZt; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbiLFSgp (ORCPT + 77 others); Tue, 6 Dec 2022 13:36:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiLFSg2 (ORCPT ); Tue, 6 Dec 2022 13:36:28 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B404DD65; Tue, 6 Dec 2022 10:36:26 -0800 (PST) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1670351785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vVTQ+Ap4e/KZs2xYUNBsyqF85aC6jCpJzIZ0LtrQ85k=; b=glcRjbZtMXKskaTlgnihbci7XEeagGKW4gAqUbiZx/A22Q9dduxcNX3r9oZe563RaXN7zP +rSMcc9XOIjJ7+Y9PEBekdgpwjzC/SZSfRlkBIhLrX2H6ax3iLTeYIEhVvDV5FGoN7CJ+n rPDMlG4x+XxRJfJYErvZusj5Toa0bks= Date: Tue, 6 Dec 2022 10:36:20 -0800 MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v2] bpf: Upgrade bpf_{g,s}etsockopt return values Content-Language: en-US To: Ji Rongfeng Cc: daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 12/2/22 9:39 AM, Ji Rongfeng wrote: > Returning -EINVAL almost all the time when error occurs is not very > helpful for the bpf prog to figure out what is wrong. This patch > upgrades some return values so that they will be much more helpful. > > * return -ENOPROTOOPT when optname is unsupported > > The same as {g,s}etsockopt() syscall does. Before this patch, > bpf_setsockopt(TCP_SAVED_SYN) already returns -ENOPROTOOPT, which > may confuse the user, as -EINVAL is returned on other unsupported > optnames. This patch also rejects TCP_SAVED_SYN right in > sol_tcp_sockopt() when getopt is false, since do_tcp_setsockopt() > is just the executor and it's not its duty to discover such error > in bpf. We should maintain a precise allowlist to control whether > an optname is supported and allowed to enter the executor or not. > Functions like do_tcp_setsockopt(), their behaviour are not fully > controllable by bpf. Imagine we let an optname pass, expecting > -ENOPROTOOPT will be returned, but someday that optname is > actually processed and unfortunately causes deadlock when calling > from bpf. Thus, precise access control is essential. Please leave the current -EINVAL to distinguish between optnames rejected by bpf and optnames rejected by the do_*_{get,set}sockopt(). > > * return -EOPNOTSUPP on level-related errors > > In do_ip_getsockopt(), -EOPNOTSUPP will be returned if level != > SOL_IP. In ipv6_getsockopt(), -ENOPROTOOPT will be returned if > level != SOL_IPV6. To be distinguishable, the former is chosen. I would leave this one as is also. Are you sure the do_ip_*sockopt cannot handle sk_family == AF_INET6? afaict, bpf is rejecting those optnames instead. > > * return -EBADFD when sk is not a full socket > > -EPERM or -EBUSY was an option, but in many cases one of them > will be returned, especially under level SOL_TCP. -EBADFD is the > better choice, since it is hardly returned in all cases. The bpf > prog will be able to recognize it and decide what to do next. This one makes sense and is useful.