Skip to content

Commit af06394

Browse files
committed
Revert "sys/socket.h: Fix AF_MAX"
This reverts commit 33a943e. PR: https://forum.opnsense.org/index.php?topic=52691.0 Causes reports of kernel panics the likes of: Fatal trap 12: page fault while in kernel mode cpuid = 1; apic id = 01 fault virtual address = 0x218361fa00 fault code = supervisor read data, page not present instruction pointer = 0x20:0xffffffff80c4d7a7 stack pointer = 0x28:0xfffffe00d3332ab0 frame pointer = 0x28:0xfffffe00d3332ab0 code segment = base 0x0, limit 0xfffff, type 0x1b = DPL 0, pres 1, long 1, def32 0, gran 1 processor eflags = interrupt enabled, resume, IOPL = 0 current process = 0 (netlink_socket (PID) rdi: 000000218361fa00 rsi: 0000000000000000 rdx: 0000000000000000 rcx: 000000000000000c r8: 0000000000000000 r9: 0000000000000fff rax: 0000000000000000 rbx: fffffe00d3332d40 rbp: fffffe00d3332ab0 r10: 0000000000000000 r11: 0000000000000000 r12: 0000000000000058 r13: 0000000000000058 r14: fffff80001b46000 r15: fffff8013d91b0a8 trap number = 12 panic: page fault cpuid = 1 time = 1786547747 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe00d3332800 vpanic() at vpanic+0x136/frame 0xfffffe00d3332930 panic() at panic+0x43/frame 0xfffffe00d3332990 trap_pfault() at trap_pfault+0x37d/frame 0xfffffe00d33329e0 calltrap() at calltrap+0x8/frame 0xfffffe00d33329e0 --- trap 0xc, rip = 0xffffffff80c4d7a7, rsp = 0xfffffe00d3332ab0, rbp = 0xfffffe00d3332ab0 --- counter_u64_fetch() at counter_u64_fetch+0x57/frame 0xfffffe00d3332ab0 dump_iface() at dump_iface+0x4ec/frame 0xfffffe00d3332b50 dump_cb() at dump_cb+0x1c/frame 0xfffffe00d3332b70 if_foreach_sleep() at if_foreach_sleep+0x227/frame 0xfffffe00d3332bf0 rtnl_handle_getlink() at rtnl_handle_getlink+0x257/frame 0xfffffe00d3332cd0 rtnl_handle_message() at rtnl_handle_message+0x195/frame 0xfffffe00d3332d30 nl_taskqueue_handler() at nl_taskqueue_handler+0x469/frame 0xfffffe00d3332e40 taskqueue_run_locked() at taskqueue_run_locked+0x182/frame 0xfffffe00d3332ec0 taskqueue_thread_loop() at taskqueue_thread_loop+0xc2/frame 0xfffffe00d3332ef0 fork_exit() at fork_exit+0x7b/frame 0xfffffe00d3332f30 fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe00d3332f30 --- trap 0x6, rip = 0x1c1f86083327, rsp = 0x101, rbp = 0x2710 --- KDB: enter: panic
1 parent 7067fa3 commit af06394

9 files changed

Lines changed: 14 additions & 16 deletions

File tree

lib/libifconfig/libifconfig.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ifconfig_open(void)
8181
if (h == NULL) {
8282
return (NULL);
8383
}
84-
for (int i = 0; i < AF_MAX; i++) {
84+
for (int i = 0; i <= AF_MAX; i++) {
8585
h->sockets[i] = -1;
8686
}
8787

@@ -92,7 +92,7 @@ void
9292
ifconfig_close(ifconfig_handle_t *h)
9393
{
9494

95-
for (int i = 0; i < AF_MAX; i++) {
95+
for (int i = 0; i <= AF_MAX; i++) {
9696
if (h->sockets[i] != -1) {
9797
(void)close(h->sockets[i]);
9898
}

lib/libifconfig/libifconfig_internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int
7878
ifconfig_socket(ifconfig_handle_t *h, const int addressfamily, int *s)
7979
{
8080

81-
if (addressfamily >= AF_MAX) {
81+
if (addressfamily > AF_MAX) {
8282
h->error.errtype = SOCKET;
8383
h->error.errcode = EINVAL;
8484
return (-1);

sys/kern/vfs_export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
160160
saddr = (struct sockaddr *) (np + 1);
161161
if ((error = copyin(argp->ex_addr, saddr, argp->ex_addrlen)))
162162
goto out;
163-
if (saddr->sa_family == AF_UNSPEC || saddr->sa_family >= AF_MAX) {
163+
if (saddr->sa_family == AF_UNSPEC || saddr->sa_family > AF_MAX) {
164164
error = EINVAL;
165165
vfs_mount_error(mp, "Invalid saddr->sa_family: %d");
166166
goto out;

sys/net/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ rt_updatemtu(struct ifnet *ifp)
520520
* Unfortunately the only way to do this is to traverse all
521521
* routing tables in all fibs/domains.
522522
*/
523-
for (i = 1; i < AF_MAX; i++) {
523+
for (i = 1; i <= AF_MAX; i++) {
524524
mtu = if_getmtu_family(ifp, i);
525525
for (j = 0; j < rt_numfibs; j++) {
526526
rnh = rt_tables_get_rnh(j, i);

sys/net/route/route_ddb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ DB_SHOW_COMMAND(routetable, db_show_routetable)
174174
i = lim = addr;
175175
else {
176176
i = 1;
177-
lim = AF_MAX - 1;
177+
lim = AF_MAX;
178178
}
179179

180180
for (; i <= lim; i++) {

sys/net/route/route_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ rib_foreach_table_walk(int family, bool wlock, rib_walktree_f_t *wa_f,
184184
continue;
185185
}
186186

187-
for (int i = 1; i < AF_MAX; i++)
187+
for (int i = 1; i <= AF_MAX; i++)
188188
rib_walk_ext(fibnum, i, wlock, wa_f, hook_f, arg);
189189
}
190190
}
@@ -206,7 +206,7 @@ rib_foreach_table_walk_del(int family, rib_filter_f_t *filter_f, void *arg)
206206
continue;
207207
}
208208

209-
for (int i = 1; i < AF_MAX; i++)
209+
for (int i = 1; i <= AF_MAX; i++)
210210
rib_walk_del(fibnum, i, filter_f, arg, 0);
211211
}
212212
}

sys/net/rtsock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,7 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS)
26202620
} else if (namelen != 3)
26212621
return ((namelen < 3) ? EISDIR : ENOTDIR);
26222622
af = name[0];
2623-
if (af >= AF_MAX)
2623+
if (af > AF_MAX)
26242624
return (EINVAL);
26252625
bzero(&w, sizeof(w));
26262626
w.w_op = name[1];
@@ -2644,7 +2644,7 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS)
26442644
case NET_RT_FLAGS:
26452645
if (af == 0) { /* dump all tables */
26462646
i = 1;
2647-
lim = AF_MAX - 1;
2647+
lim = AF_MAX;
26482648
} else /* dump only one table */
26492649
i = lim = af;
26502650

sys/netlink/route/rt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ rtnl_handle_newroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
973973
/* pre-2.6.19 Linux API compatibility */
974974
if (attrs.rtm_table > 0 && attrs.rta_table == 0)
975975
attrs.rta_table = attrs.rtm_table;
976-
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family >= AF_MAX) {
976+
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) {
977977
NLMSG_REPORT_ERR_MSG(npt, "invalid fib");
978978
return (EINVAL);
979979
}
@@ -1036,7 +1036,7 @@ rtnl_handle_delroute(struct nlmsghdr *hdr, struct nlpcb *nlp,
10361036
return (ESRCH);
10371037
}
10381038

1039-
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family >= AF_MAX) {
1039+
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) {
10401040
NLMSG_REPORT_ERR_MSG(npt, "invalid fib");
10411041
return (EINVAL);
10421042
}
@@ -1059,7 +1059,7 @@ rtnl_handle_getroute(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *
10591059
if (error != 0)
10601060
return (error);
10611061

1062-
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family >= AF_MAX) {
1062+
if (attrs.rta_table >= V_rt_numfibs || attrs.rtm_family > AF_MAX) {
10631063
NLMSG_REPORT_ERR_MSG(npt, "invalid fib");
10641064
return (EINVAL);
10651065
}

sys/sys/socket.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ struct accept_filter_arg {
271271
#define AF_HYPERV 43 /* HyperV sockets */
272272
#define AF_DIVERT 44 /* divert(4) */
273273
#define AF_IPFWLOG 46
274-
275-
#define AF_MAX 47
276-
274+
#define AF_MAX 46
277275
/*
278276
* When allocating a new AF_ constant, please only allocate
279277
* even numbered constants for FreeBSD until 134 as odd numbered AF_

0 commit comments

Comments
 (0)