NetBSD Problem Report #58380

From www@netbsd.org  Sat Jun 29 11:23:04 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 969D81A923C
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 29 Jun 2024 11:23:04 +0000 (UTC)
Message-Id: <20240629112303.848641A923E@mollari.NetBSD.org>
Date: Sat, 29 Jun 2024 11:23:03 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: net_stats.h is type-unsafe due to unnecessary void *
X-Send-Pr-Version: www-1.0

>Number:         58380
>Category:       kern
>Synopsis:       net_stats.h is type-unsafe due to unnecessary void *
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 29 11:25:00 +0000 2024
>Last-Modified:  Sat Jun 29 13:05:05 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10
>Organization:
The NetBSD void*ation
>Environment:
>Description:
sys/net/net_stats.h defines

typedef void *net_stat_ref_t;

which hides type errors in usage of any API routines that accept net_stat_ref_t.

For example, in if_scx.c, we have:

   1402 				if_statinc_ref(ifp, if_oerrors);

https://nxr.netbsd.org/xref/src/sys/arch/arm/sociox/if_scx.c?r=1.43#1402

This compiles just fine, but won't work very well at runtime!
>How-To-Repeat:
code inspection
>Fix:
typedef struct net_stat_ref {
	uint64_t nsr_stat[];
} *net_stat_ref_t;

Also maybe make the macros in net_stats.h be inline functions instead -- I don't see any reason why they need to be macros.

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58380 CVS commit: src/sys/arch/arm/sociox
Date: Sat, 29 Jun 2024 11:27:12 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 11:27:12 UTC 2024

 Modified Files:
 	src/sys/arch/arm/sociox: if_scx.c

 Log Message:
 scx(4): Fix if_statinc call.

 We don't have a reference to the local statistics counters, so we
 can't use if_statinc_ref.  But, because net_stat_ref_t is just an
 alias for void *, the compiler doesn't detect this mistake.

 PR kern/58380


 To generate a diff of this commit:
 cvs rdiff -u -r1.43 -r1.44 src/sys/arch/arm/sociox/if_scx.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58380 CVS commit: src/sys/netinet
Date: Sat, 29 Jun 2024 12:59:09 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 12:59:09 UTC 2024

 Modified Files:
 	src/sys/netinet: if_arp.c ip_flow.c ip_input.c raw_ip.c tcp_input.c
 	    tcp_output.c tcp_syncache.c

 Log Message:
 netinet: Use _NET_STAT* API instead of direct array access.

 PR kern/58380


 To generate a diff of this commit:
 cvs rdiff -u -r1.312 -r1.313 src/sys/netinet/if_arp.c
 cvs rdiff -u -r1.85 -r1.86 src/sys/netinet/ip_flow.c
 cvs rdiff -u -r1.402 -r1.403 src/sys/netinet/ip_input.c
 cvs rdiff -u -r1.184 -r1.185 src/sys/netinet/raw_ip.c
 cvs rdiff -u -r1.438 -r1.439 src/sys/netinet/tcp_input.c
 cvs rdiff -u -r1.219 -r1.220 src/sys/netinet/tcp_output.c
 cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/tcp_syncache.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58380 CVS commit: src/sys/netinet6
Date: Sat, 29 Jun 2024 13:00:45 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 13:00:45 UTC 2024

 Modified Files:
 	src/sys/netinet6: icmp6.c ip6_flow.c ip6_forward.c ip6_input.c

 Log Message:
 netinet6: Use _NET_STAT* API instead of direct array access.

 XXX Exception: ip6flow_addstats_rt _assigns_ one of the `statistics'
 to the current count of ip6 flows in use, and we don't have anything
 in the _NET_STAT* API for that.  So for now I abuse the abstraction,
 until we sort out this one exceptional case properly.

 PR kern/58380


 To generate a diff of this commit:
 cvs rdiff -u -r1.256 -r1.257 src/sys/netinet6/icmp6.c
 cvs rdiff -u -r1.42 -r1.43 src/sys/netinet6/ip6_flow.c
 cvs rdiff -u -r1.102 -r1.103 src/sys/netinet6/ip6_forward.c
 cvs rdiff -u -r1.227 -r1.228 src/sys/netinet6/ip6_input.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58380 CVS commit: src/sys/netipsec
Date: Sat, 29 Jun 2024 13:01:14 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 13:01:14 UTC 2024

 Modified Files:
 	src/sys/netipsec: key.c keysock.c

 Log Message:
 netipsec: Use _NET_STAT* API instead of direct array access.

 PR kern/58380


 To generate a diff of this commit:
 cvs rdiff -u -r1.282 -r1.283 src/sys/netipsec/key.c
 cvs rdiff -u -r1.70 -r1.71 src/sys/netipsec/keysock.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58380 CVS commit: src/sys/net
Date: Sat, 29 Jun 2024 13:01:30 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 13:01:30 UTC 2024

 Modified Files:
 	src/sys/net: net_stats.h

 Log Message:
 net_stats(9): Make this API slightly more type-safe.

 TBD: Convert the macros to inline functions for better type-safety.

 PR kern/58380


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/sys/net/net_stats.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.