From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6671C77B78 for ; Wed, 26 Apr 2023 18:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjDZSHY (ORCPT ); Wed, 26 Apr 2023 14:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231377AbjDZSHX (ORCPT ); Wed, 26 Apr 2023 14:07:23 -0400 Received: from out-29.mta1.migadu.com (out-29.mta1.migadu.com [IPv6:2001:41d0:203:375::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CB265BBA for ; Wed, 26 Apr 2023 11:07:22 -0700 (PDT) Message-ID: <9864acbe-7118-d7b5-0287-7737f3135c30@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1682532440; 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=EGNH9441lUhP9/cCCGkPSXJhzwT8yodRCtUyd+kXhGQ=; b=mRxRzX5W5YlHFf6QHAHRLtKzaXX/S3j75Kh48KjYfJoz8PjsLi8cBmPHv4tSsSbk94TmKR 6En1OM+VmG3606qwLZuSaMxxrcB+XZDMLUHD3jGCgKpE+Gfw8Zt1/DsyWS0AMtkDTVxNFw ZYiI0ZK64t84ucmZ0iosUC90pAK3huw= Date: Wed, 26 Apr 2023 11:07:13 -0700 MIME-Version: 1.0 Subject: Re: [PATCH bpf-next 3/6] bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen Content-Language: en-US To: Stanislav Fomichev Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com, jolsa@kernel.org, Martin KaFai Lau , Daniel Borkmann References: <20230418225343.553806-1-sdf@google.com> <20230418225343.553806-4-sdf@google.com> <4a2e1b70-9055-f5d9-c286-3e5760f06811@iogearbox.net> <4d5e33ff-9e0a-aa2b-0482-49bda0d7fade@linux.dev> 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 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 4/26/23 10:27 AM, Stanislav Fomichev wrote: >>> As per above, I'll stick a line to the dmest (similar >>> bpf_warn_invalid_xdp_action), at least to record that this has >>> happened once. >>> LMK if you or Danial still don't see a value in printing this.. >> >> pr_info_once? hmm... I think it is ok-ish. At least not a warning. >> >> I think almost all of the time the bpf prog forgets to set it to 0 for the long >> optval that it has no interest in. However, to suppress this pr_info_once, >> setting optlen to 0 will disable the following cgroup-bpf prog from using the >> optval as read-only. The case that the printk that may flag is that the bpf prog >> did indeed want to change the long optval? > > The case we want to printk is where the prog changes some byte in the > first 4k range of the optval and does not touch optlen (or maybe > adjusts optlen to be >PAGE_SIZE and I agree that it feels super corner-casy; but it feels like without > some kind of hint, it would be impossible to figure out why it doesn't > work. Or am I overblowing it? I don't have a better idea how to flag this 'changing the first few bytes of a long optval is not supported' either. I guess pr_info_once is ok-ish for now to stop the bleeding in the most common case. If it can separate the original_optlen > PAGE_SIZE case (ignore and no -EFAULT), the message probably needs to be less alarming. "bpf setsockopt returned unexpected optlen" may cause confusion when the bpf prog did not touch the optval and optlen. Hopefully this pr_info_once will disappear when the cgroup-bpf prog can directly read/write the optval without pre-allocation.