From patchwork Fri Jun 28 08:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13715719 X-Patchwork-Delegate: bpf@iogearbox.net Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C13014AD35 for ; Fri, 28 Jun 2024 08:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719564546; cv=none; b=ZaFWrKlOf/LxQ1UuEvnXKm/4d2v8M1zkt2vhSOb0BnII6+eIFlibogvIYUWfopnqT+yhrKauCqsxUAMR/F+22v3MvWDLSpXNOd9YawqQabPSz5yl0OyFb3sujpuQEWRkrLhmFVwjKy1EYCjxkgwnZl0ayyD2woat0NlWL0x+VKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719564546; c=relaxed/simple; bh=Jmp15m7DL/9CIirMtc/sXhw+FIwwKVeUs0zdTAHo3g4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ifiLCCsD6Bcl35U9+8TJ1HcQqZe5dAu1C67w5n0ctmEhRDRtqCuXYU+eILPrXpycXy3HfYq6bCp23T5fU2mO/wEvWbh5LcD5fuSOoVjtpbz0vrBIVRLI0b1ivcLU7++EWNGnYfX9/fuyn4WVCTTZfBbJEJgkEdbpRpVWDcXLVsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=45YlAJLC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ss46+fOS; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="45YlAJLC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ss46+fOS" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719564541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uu4Q3+wslqXJvO6xMEb3kL901uruUkEDytAMQS77wrg=; b=45YlAJLCUR85ZakeNyO+9Xe9o/lsIolFo6S5TFzbVNbpDax6AcNUFBip1PfP/ELDEZXIXC k3WqJMsJJKJnzrcMjyWR7koRzx0mP76HTletKer6zyMcF5oqnCogrkovvDpYF38HVQTRdH 8sFTnSkhSL4NExPvrNrL7tgT71XC29coJdBqyjn9U7TjihgZyVY7puCSLh79cMhf6WzyAU zqk7n3GxgtzxhUUhpd66iSkFWauGk14LDW8jRi2Y00jE/VyQXw8ooTJQL8y6l+++3cTYoE vh3NM3eCvwlRE4JfySQNww9Sckz0+tPE8JinKFJ+JpY2QvW1RffAdfejglxCbQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719564541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uu4Q3+wslqXJvO6xMEb3kL901uruUkEDytAMQS77wrg=; b=Ss46+fOS28TulJPiW5W8IOxg7adK9kCMmlfmFGL7TF/hyPESzYqjSeUVWxxfkkl2zgKegy 0+2GSw2bYYNEQcAQ== To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Hao Luo , Jiri Olsa , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Thomas Gleixner , Yonghong Song , Sebastian Andrzej Siewior , kernel test robot Subject: [PATCH bpf-next 1/3] bpf: Add casts to keep sparse quiet. Date: Fri, 28 Jun 2024 10:40:59 +0200 Message-ID: <20240628084857.1719108-2-bigeasy@linutronix.de> In-Reply-To: <20240628084857.1719108-1-bigeasy@linutronix.de> References: <20240628084857.1719108-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net sparse complains about wrong data types within the BPF callbacks. Functions like bpf_l3_csum_replace() are invoked with a specific set of arguments and its further usage is based on a flag. So it can not be set right upfront. There is also access to variables in struct bpf_nh_params and struct bpf_xfrm_state which should be __be32. The content comes directly from the BPF program so conversion is already right. Add __force casts for the right data type and update the members in struct bpf_xfrm_state and bpf_nh_params in order to keep sparse happy. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202406261217.A4hdCnYa-lkp@intel.com Signed-off-by: Sebastian Andrzej Siewior --- include/linux/filter.h | 2 +- include/uapi/linux/bpf.h | 6 +++--- net/core/filter.c | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index c0349522de8fb..9a96019376b67 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -728,7 +728,7 @@ struct bpf_skb_data_end { struct bpf_nh_params { u32 nh_family; union { - u32 ipv4_nh; + __be32 ipv4_nh; struct in6_addr ipv6_nh; }; }; diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 25ea393cf084b..f45b03706e4e9 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -6290,12 +6290,12 @@ struct bpf_tunnel_key { */ struct bpf_xfrm_state { __u32 reqid; - __u32 spi; /* Stored in network byte order */ + __be32 spi; /* Stored in network byte order */ __u16 family; __u16 ext; /* Padding, future use. */ union { - __u32 remote_ipv4; /* Stored in network byte order */ - __u32 remote_ipv6[4]; /* Stored in network byte order */ + __be32 remote_ipv4; /* Stored in network byte order */ + __be32 remote_ipv6[4]; /* Stored in network byte order */ }; }; diff --git a/net/core/filter.c b/net/core/filter.c index eb1c4425c06f3..11939971f3c6a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -1939,13 +1939,13 @@ BPF_CALL_5(bpf_l3_csum_replace, struct sk_buff *, skb, u32, offset, if (unlikely(from != 0)) return -EINVAL; - csum_replace_by_diff(ptr, to); + csum_replace_by_diff(ptr, (__force __wsum)to); break; case 2: - csum_replace2(ptr, from, to); + csum_replace2(ptr, (__force __be16)from, (__force __be16)to); break; case 4: - csum_replace4(ptr, from, to); + csum_replace4(ptr, (__force __be32)from, (__force __be32)to); break; default: return -EINVAL; @@ -1990,13 +1990,15 @@ BPF_CALL_5(bpf_l4_csum_replace, struct sk_buff *, skb, u32, offset, if (unlikely(from != 0)) return -EINVAL; - inet_proto_csum_replace_by_diff(ptr, skb, to, is_pseudo); + inet_proto_csum_replace_by_diff(ptr, skb, (__force __wsum)to, is_pseudo); break; case 2: - inet_proto_csum_replace2(ptr, skb, from, to, is_pseudo); + inet_proto_csum_replace2(ptr, skb, (__force __be16)from, (__force __be16)to, + is_pseudo); break; case 4: - inet_proto_csum_replace4(ptr, skb, from, to, is_pseudo); + inet_proto_csum_replace4(ptr, skb, (__force __be32)from, (__force __be32)to, + is_pseudo); break; default: return -EINVAL; @@ -2046,7 +2048,7 @@ BPF_CALL_5(bpf_csum_diff, __be32 *, from, u32, from_size, ret = csum_partial(sp->diff, diff_size, seed); local_unlock_nested_bh(&bpf_sp.bh_lock); - return ret; + return (__force __u32)ret; } static const struct bpf_func_proto bpf_csum_diff_proto = { @@ -2068,7 +2070,7 @@ BPF_CALL_2(bpf_csum_update, struct sk_buff *, skb, __wsum, csum) * as emulating csum_sub() can be done from the eBPF program. */ if (skb->ip_summed == CHECKSUM_COMPLETE) - return (skb->csum = csum_add(skb->csum, csum)); + return (__force __u32)(skb->csum = csum_add(skb->csum, csum)); return -ENOTSUPP; } From patchwork Fri Jun 28 08:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13715718 X-Patchwork-Delegate: bpf@iogearbox.net Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C16F14B952 for ; Fri, 28 Jun 2024 08:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719564546; cv=none; b=Y+FOrB7Zsd5BGXFpbgUcSB3ULRYokpnf31zP+d4Ydq/rV4Uq0wU9HLn10SRDpNkbE1MFWbZgyQqZuOIpGuu8AZ1PkEQ8SVjGBFpYf3r6p0057e9RhQJ8ThBsI96kcIerJQ5RUb9RAy2W/a0cpp3bEfsXP4m6uvenXPLaJSaVdlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719564546; c=relaxed/simple; bh=I3uOl4cDbnhxozovBfnc/iAY8w4Qu+WZ3mDXJZRgUtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZXFA7fy7yOYSUKUohZuXKbmMJA+Rs4X4Pft66JAZgsWQjQvmWJcTXBPJloY9QFlfIrrbT9B4Rfd3XAh1Rod3oJjcbcS8jZDQeTpIBj2B9Ty2usWeVE73wohBK2zsYxR/3bBO9O/j0LhiQsg+Hxo5T0V1A8PyAL5+U+whBGu2HJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0L/aaEke; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=87XDwh3K; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0L/aaEke"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="87XDwh3K" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719564542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JplfBwznUpua9J2/WRPUveXnK3sjto8+qhgTRlfPCcc=; b=0L/aaEkeFtN84GH1Sb1xCP1zN8GFtSYYzQMKAwTL3a5tl1yHHG6jfE/NJtUmmYgmuqoSEO 0DklkzxyAtHCdfLqV3fcGK4GNqUa7pD6trlGK+Pjylif4bkwFaSWphUEJ+uTUESbdRu2h1 gkBkFAZLWhLmYxQmsZDPlF6crHwVDkQ6GT5rGtqacS3BWZG0VTM/F9B5Qkdr+iGidD/UQO OQniurWYG3MmRiQ1HHbEFERh8j9q339sWPooj/wj0/4aXnuWsIT1MmH/j2lgugCXmOfCP3 k0ph1DgoUBQlhzb5EEv3q8A0MPgar/tDoxSkAaMYEQ0/jc5TTUBmcvWzzRBJ/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719564542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JplfBwznUpua9J2/WRPUveXnK3sjto8+qhgTRlfPCcc=; b=87XDwh3Ke80fDJXML/qqYTehulo22zEi320DuIxODN5qRIzEzK/8pBPQlJPOVpcRpF0rGC mj+BrUPkxttxyNBQ== To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Hao Luo , Jiri Olsa , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Thomas Gleixner , Yonghong Song , Sebastian Andrzej Siewior , Masami Hiramatsu , Mathieu Desnoyers , Steven Rostedt Subject: [PATCH bpf-next 2/3] bpf: Move a few bpf_func_proto declarations. Date: Fri, 28 Jun 2024 10:41:00 +0200 Message-ID: <20240628084857.1719108-3-bigeasy@linutronix.de> In-Reply-To: <20240628084857.1719108-1-bigeasy@linutronix.de> References: <20240628084857.1719108-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net sparse complains about missing declarations and a few of them are in another .c file. One has no other declaration because it is used localy and marked weak because it might be defined in another .c file. Move the declarations from bpf_trace.c to a common place and add one for bpf_sk_storage_get_cg_sock_proto. After this change there are only a few missing declartions within the __bpf_kfunc_start_defs() block which explictlty disables this kind of warning for the compiler. I am not aware of something similar for sparse so I guess are stuck with them unless we add them. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Steven Rostedt Signed-off-by: Sebastian Andrzej Siewior --- include/linux/bpf.h | 5 +++++ kernel/trace/bpf_trace.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index a834f4b761bc5..50074009d0860 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -840,6 +840,11 @@ struct bpf_func_proto { bool (*allowed)(const struct bpf_prog *prog); }; +extern const struct bpf_func_proto bpf_xdp_get_buff_len_trace_proto; +extern const struct bpf_func_proto bpf_skb_output_proto; +extern const struct bpf_func_proto bpf_xdp_output_proto; +extern const struct bpf_func_proto bpf_sk_storage_get_cg_sock_proto; + /* bpf_context is intentionally undefined structure. Pointer to bpf_context is * the first argument to eBPF programs. * For socket filters: 'struct bpf_context *' == 'struct sk_buff *' diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index d1daeab1bbc14..d8d7ee6b06a6f 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1951,10 +1951,6 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_raw_tp = { .arg5_type = ARG_CONST_SIZE_OR_ZERO, }; -extern const struct bpf_func_proto bpf_skb_output_proto; -extern const struct bpf_func_proto bpf_xdp_output_proto; -extern const struct bpf_func_proto bpf_xdp_get_buff_len_trace_proto; - BPF_CALL_3(bpf_get_stackid_raw_tp, struct bpf_raw_tracepoint_args *, args, struct bpf_map *, map, u64, flags) { From patchwork Fri Jun 28 08:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13715717 X-Patchwork-Delegate: bpf@iogearbox.net Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C1B714B96F for ; Fri, 28 Jun 2024 08:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719564546; cv=none; b=PnqgJLaLQ1/LPKKTsQgQ7OviVrIQkwCaYIRTmL/r3Mcw1RRU5T94Y96/o8w0zuTDt49mg5a9oaZ0+cdEjjf6UQM42EMGT3ncFuQvDsW4w/kwupqu7pQCKKuwuMJ5JCgTLCzQd9Rp3cog8PfswS8cr/PXQzon3VzEImuBOrq0oNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719564546; c=relaxed/simple; bh=MFo3CJUMjfzzSqAXEUbXuEDeMF7DaLrx+fnjBX+zwQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oxwhhe8wALhQ+m5PrWcOhsjSN5PBPHvoW62EeEI22+9dX0swinc4E+sY0nWLS1Beloet1GDDXIoeh3/iFMD7ItTK5znBy9BHe9Bko7QARkhc1RCKcDJSYhN7GChD3suB2RAg906VURdQFHVBI55LfbnyMu8Ufqkz2nojcW/b8U0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1O2U+3pY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XjVylIi9; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1O2U+3pY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XjVylIi9" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719564542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m6Nra70WiqjDzMNgjpIPCKOgbH+ZimhecuOESN4J+fQ=; b=1O2U+3pYFRMYvLzM5k5nGvbwdOf5fnolPT7LleuzV+4msDPBP2gSSpv990q0qUV7AaATcc 4sNh9tWa0q5YS6ljel6hcfA7fXDeKmadO6TG5RG9KXqHirSGNiR9OsIQxfbSi2sxWkfLVl ANg/bvKdBQcAF+oQplkThjJTYbtqXuPJ9GvK0+UZPbfPDnUDB1sP6jZr6DN4lbFzVuxPZ1 i2Bd52OFprTtiBTgbhscGJcewsA7NZM3ab6N43+HDXsRxOu6POcEFY48SAEeJAMFxSxJC2 g877FDssDdAJyHrv4n8wBhGluIQIY/wHyy39VCrpuep7m6ScMu4Xm//sOHjl8w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719564542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m6Nra70WiqjDzMNgjpIPCKOgbH+ZimhecuOESN4J+fQ=; b=XjVylIi9/VKcCCLs4X0e1MPXxMQdpmXEPHfcAi+e+7OTvD5v/d29z36LlbxFbfdve0g4PB 5tJsbBp8U0GU3jAQ== To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Hao Luo , Jiri Olsa , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Thomas Gleixner , Yonghong Song , Sebastian Andrzej Siewior Subject: [PATCH bpf-next 3/3] bpf: Implement bpf_check_basics_ok() as a macro. Date: Fri, 28 Jun 2024 10:41:01 +0200 Message-ID: <20240628084857.1719108-4-bigeasy@linutronix.de> In-Reply-To: <20240628084857.1719108-1-bigeasy@linutronix.de> References: <20240628084857.1719108-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net sparse complains about the argument type for filter that is passed to bpf_check_basics_ok(). There are two users of the function where the variable is with __user attribute one without. The pointer is only checked against NULL so there is no access to the content and so no need for any user-wrapper. Adding the __user to the declaration doesn't solve anything because there is one kernel user so it will be wrong again. Splitting the function in two seems an overkill because the function is small and simple. Make a macro based on the function which does not trigger a sparse warning. The change to a macro and "unsigned int" -> "u16" for `flen' alters gcc's code generation a bit. Signed-off-by: Sebastian Andrzej Siewior --- net/core/filter.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 11939971f3c6a..72ccce80f9f15 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -1035,16 +1035,20 @@ static bool chk_code_allowed(u16 code_to_probe) return codes[code_to_probe]; } -static bool bpf_check_basics_ok(const struct sock_filter *filter, - unsigned int flen) -{ - if (filter == NULL) - return false; - if (flen == 0 || flen > BPF_MAXINSNS) - return false; - - return true; -} + /* macro instead of a function to avoid woring about _filter which might be a + * user or kernel pointer. It does not matter for the NULL check. + */ +#define bpf_check_basics_ok(fprog_filter, fprog_flen) \ +({ \ + bool __ret_ = true; \ + u16 __flen = fprog_flen; \ + \ + if (!(fprog_filter)) \ + __ret = false; \ + else if (__flen == 0 || __flen > BPF_MAXINSNS) \ + __ret = false; \ + __ret; \ +}) /** * bpf_check_classic - verify socket filter code