Skip to content

Commit

Permalink
Merge branch 'freebsd/current/main' into hardened/current/master
Browse files Browse the repository at this point in the history
  • Loading branch information
HardenedBSD Sync Service committed May 31, 2022
2 parents 38395d9 + d18b4be commit 9802f5e
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 82 deletions.
6 changes: 0 additions & 6 deletions sys/fs/nfsclient/nfs_clvnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,11 +1323,6 @@ nfs_lookup(struct vop_lookup_args *ap)
}

openmode = 0;
#if 0
/*
* The use of LookupOpen breaks some builds. It is disabled
* until that is fixed.
*/
/*
* If this an NFSv4.1/4.2 mount using the "oneopenown" mount
* option, it is possible to do the Open operation in the same
Expand All @@ -1347,7 +1342,6 @@ nfs_lookup(struct vop_lookup_args *ap)
openmode |= NFSV4OPEN_ACCESSWRITE;
}
NFSUNLOCKMNT(nmp);
#endif

newvp = NULLVP;
NFSINCRGLOBAL(nfsstatsv1.lookupcache_misses);
Expand Down
43 changes: 38 additions & 5 deletions sys/net/if_llatbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,41 @@ lltable_sysctl_dumparp(int af, struct sysctl_req *wr)
return (error);
}

/*
* Adds a mbuf to hold queue. Drops old packets if the queue is full.
*
* Returns the number of held packets that were dropped.
*/
size_t
lltable_append_entry_queue(struct llentry *lle, struct mbuf *m,
size_t maxheld)
{
size_t pkts_dropped = 0;

LLE_WLOCK_ASSERT(lle);

while (lle->la_numheld >= maxheld && lle->la_hold != NULL) {
struct mbuf *next = lle->la_hold->m_nextpkt;
m_freem(lle->la_hold);
lle->la_hold = next;
lle->la_numheld--;
pkts_dropped++;
}

if (lle->la_hold != NULL) {
struct mbuf *curr = lle->la_hold;
while (curr->m_nextpkt != NULL)
curr = curr->m_nextpkt;
curr->m_nextpkt = m;
} else
lle->la_hold = m;

lle->la_numheld++;

return pkts_dropped;
}


/*
* Common function helpers for chained hash table.
*/
Expand Down Expand Up @@ -285,14 +320,12 @@ llentries_unlink(struct lltable *llt, struct llentries *head)
size_t
lltable_drop_entry_queue(struct llentry *lle)
{
size_t pkts_dropped;
struct mbuf *next;
size_t pkts_dropped = 0;

LLE_WLOCK_ASSERT(lle);

pkts_dropped = 0;
while ((lle->la_numheld > 0) && (lle->la_hold != NULL)) {
next = lle->la_hold->m_nextpkt;
while (lle->la_hold != NULL) {
struct mbuf *next = lle->la_hold->m_nextpkt;
m_freem(lle->la_hold);
lle->la_hold = next;
lle->la_numheld--;
Expand Down
2 changes: 2 additions & 0 deletions sys/net/if_llatbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ void lltable_link(struct lltable *llt);
void lltable_prefix_free(int, struct sockaddr *,
struct sockaddr *, u_int);
int lltable_sysctl_dumparp(int, struct sysctl_req *);
size_t lltable_append_entry_queue(struct llentry *,
struct mbuf *, size_t);

struct lltable *in_lltable_get(struct ifnet *ifp);
struct lltable *in6_lltable_get(struct ifnet *ifp);
Expand Down
1 change: 1 addition & 0 deletions sys/netinet/icmp6.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ struct icmp6stat {
uint64_t icp6s_tooshort; /* packet < sizeof(struct icmp6_hdr) */
uint64_t icp6s_checksum; /* bad checksum */
uint64_t icp6s_badlen; /* calculated bound mismatch */
uint64_t icp6s_dropped; /* # of packets dropped waiting for a resolution */
/*
* number of responses: this member is inherited from netinet code, but
* for netinet6 code, it is already available in icp6s_outhist[].
Expand Down
23 changes: 4 additions & 19 deletions sys/netinet/if_ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ arpresolve_full(struct ifnet *ifp, int is_gw, int flags, struct mbuf *m,
struct llentry **plle)
{
struct llentry *la = NULL, *la_tmp;
struct mbuf *curr = NULL;
struct mbuf *next = NULL;
int error, renew;
char *lladdr;
int ll_len;
Expand Down Expand Up @@ -533,31 +531,18 @@ arpresolve_full(struct ifnet *ifp, int is_gw, int flags, struct mbuf *m,
}

renew = (la->la_asked == 0 || la->la_expire != time_uptime);

/*
* There is an arptab entry, but no ethernet address
* response yet. Add the mbuf to the list, dropping
* the oldest packet if we have exceeded the system
* setting.
*/
if (m != NULL) {
if (la->la_numheld >= V_arp_maxhold) {
if (la->la_hold != NULL) {
next = la->la_hold->m_nextpkt;
m_freem(la->la_hold);
la->la_hold = next;
la->la_numheld--;
ARPSTAT_INC(dropped);
}
}
if (la->la_hold != NULL) {
curr = la->la_hold;
while (curr->m_nextpkt != NULL)
curr = curr->m_nextpkt;
curr->m_nextpkt = m;
} else
la->la_hold = m;
la->la_numheld++;
size_t dropped = lltable_append_entry_queue(la, m, V_arp_maxhold);
ARPSTAT_ADD(dropped, dropped);
}

/*
* Return EWOULDBLOCK if we have tried less than arp_maxtries. It
* will be masked by ether_output(). Return EHOSTDOWN/EHOSTUNREACH
Expand Down
53 changes: 11 additions & 42 deletions sys/netinet6/nd6.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ static void nd6_free(struct llentry **, int);
static void nd6_free_redirect(const struct llentry *);
static void nd6_llinfo_timer(void *);
static void nd6_llinfo_settimer_locked(struct llentry *, long);
static void clear_llinfo_pqueue(struct llentry *);
static int nd6_resolve_slow(struct ifnet *, int, int, struct mbuf *,
const struct sockaddr_in6 *, u_char *, uint32_t *, struct llentry **);
static int nd6_need_cache(struct ifnet *);
Expand Down Expand Up @@ -804,18 +803,19 @@ nd6_llinfo_timer(void *arg)
/* Send NS to multicast address */
pdst = NULL;
} else {
struct mbuf *m = ln->la_hold;
if (m) {
struct mbuf *m0;
struct mbuf *m;

ICMP6STAT_ADD(icp6s_dropped, ln->la_numheld);

m = ln->la_hold;
if (m != NULL) {
/*
* assuming every packet in la_hold has the
* same IP header. Send error after unlock.
*/
m0 = m->m_nextpkt;
ln->la_hold = m->m_nextpkt;
m->m_nextpkt = NULL;
ln->la_hold = m0;
clear_llinfo_pqueue(ln);
ln->la_numheld--;
}
nd6_free(&ln, 0);
if (m != NULL) {
Expand Down Expand Up @@ -2199,6 +2199,7 @@ nd6_grab_holdchain(struct llentry *ln)

chain = ln->la_hold;
ln->la_hold = NULL;
ln->la_numheld = 0;

if (ln->ln_state == ND6_LLINFO_STALE) {
/*
Expand Down Expand Up @@ -2418,6 +2419,7 @@ nd6_resolve_slow(struct ifnet *ifp, int family, int flags, struct mbuf *m,
struct in6_addr *psrc, src;
int send_ns, ll_len;
char *lladdr;
size_t dropped;

NET_EPOCH_ASSERT();

Expand Down Expand Up @@ -2484,28 +2486,8 @@ nd6_resolve_slow(struct ifnet *ifp, int family, int flags, struct mbuf *m,
* packet queue in the mbuf. When it exceeds nd6_maxqueuelen,
* the oldest packet in the queue will be removed.
*/

if (lle->la_hold != NULL) {
struct mbuf *m_hold;
int i;

i = 0;
for (m_hold = lle->la_hold; m_hold; m_hold = m_hold->m_nextpkt){
i++;
if (m_hold->m_nextpkt == NULL) {
m_hold->m_nextpkt = m;
break;
}
}
while (i >= V_nd6_maxqueuelen) {
m_hold = lle->la_hold;
lle->la_hold = lle->la_hold->m_nextpkt;
m_freem(m_hold);
i--;
}
} else {
lle->la_hold = m;
}
dropped = lltable_append_entry_queue(lle, m, V_nd6_maxqueuelen);
ICMP6STAT_ADD(icp6s_dropped, dropped);

/*
* If there has been no NS for the neighbor after entering the
Expand Down Expand Up @@ -2700,19 +2682,6 @@ nd6_rem_ifa_lle(struct in6_ifaddr *ia, int all)
lltable_delete_addr(LLTABLE6(ifp), LLE_IFADDR, saddr);
}

static void
clear_llinfo_pqueue(struct llentry *ln)
{
struct mbuf *m_hold, *m_hold_next;

for (m_hold = ln->la_hold; m_hold; m_hold = m_hold_next) {
m_hold_next = m_hold->m_nextpkt;
m_freem(m_hold);
}

ln->la_hold = NULL;
}

static int
nd6_sysctl_prlist(SYSCTL_HANDLER_ARGS)
{
Expand Down
36 changes: 26 additions & 10 deletions sys/netpfil/pf/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6978,18 +6978,25 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *
if (!V_pf_status.running)
return (PF_PASS);

PF_RULES_RLOCK();

kif = (struct pfi_kkif *)ifp->if_pf_kif;

if (kif == NULL) {
if (__predict_false(kif == NULL)) {
DPFPRINTF(PF_DEBUG_URGENT,
("pf_test: kif == NULL, if_xname %s\n", ifp->if_xname));
PF_RULES_RUNLOCK();
return (PF_DROP);
}
if (kif->pfik_flags & PFI_IFLAG_SKIP)
if (kif->pfik_flags & PFI_IFLAG_SKIP) {
PF_RULES_RUNLOCK();
return (PF_PASS);
}

if (m->m_flags & M_SKIP_FIREWALL)
if (m->m_flags & M_SKIP_FIREWALL) {
PF_RULES_RUNLOCK();
return (PF_PASS);
}

memset(&pd, 0, sizeof(pd));
pd.pf_mtag = pf_find_mtag(m);
Expand All @@ -7000,10 +7007,12 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *
ifp = ifnet_byindexgen(pd.pf_mtag->if_index,
pd.pf_mtag->if_idxgen);
if (ifp == NULL || ifp->if_flags & IFF_DYING) {
PF_RULES_RUNLOCK();
m_freem(*m0);
*m0 = NULL;
return (PF_PASS);
}
PF_RULES_RUNLOCK();
(ifp->if_output)(ifp, m, sintosa(&pd.pf_mtag->dst), NULL);
*m0 = NULL;
return (PF_PASS);
Expand All @@ -7023,12 +7032,11 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *
/* But only once. We may see the packet multiple times (e.g.
* PFIL_IN/PFIL_OUT). */
pd.pf_mtag->flags &= ~PF_TAG_DUMMYNET;
PF_RULES_RUNLOCK();

return (PF_PASS);
}

PF_RULES_RLOCK();

if (__predict_false(ip_divert_ptr != NULL) &&
((ipfwtag = m_tag_locate(m, MTAG_IPFW_RULE, 0, NULL)) != NULL)) {
struct ipfw_rule_ref *rr = (struct ipfw_rule_ref *)(ipfwtag+1);
Expand Down Expand Up @@ -7468,17 +7476,24 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
if (!V_pf_status.running)
return (PF_PASS);

PF_RULES_RLOCK();

kif = (struct pfi_kkif *)ifp->if_pf_kif;
if (kif == NULL) {
if (__predict_false(kif == NULL)) {
DPFPRINTF(PF_DEBUG_URGENT,
("pf_test6: kif == NULL, if_xname %s\n", ifp->if_xname));
PF_RULES_RUNLOCK();
return (PF_DROP);
}
if (kif->pfik_flags & PFI_IFLAG_SKIP)
if (kif->pfik_flags & PFI_IFLAG_SKIP) {
PF_RULES_RUNLOCK();
return (PF_PASS);
}

if (m->m_flags & M_SKIP_FIREWALL)
if (m->m_flags & M_SKIP_FIREWALL) {
PF_RULES_RUNLOCK();
return (PF_PASS);
}

memset(&pd, 0, sizeof(pd));
pd.pf_mtag = pf_find_mtag(m);
Expand All @@ -7489,10 +7504,12 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
ifp = ifnet_byindexgen(pd.pf_mtag->if_index,
pd.pf_mtag->if_idxgen);
if (ifp == NULL || ifp->if_flags & IFF_DYING) {
PF_RULES_RUNLOCK();
m_freem(*m0);
*m0 = NULL;
return (PF_PASS);
}
PF_RULES_RUNLOCK();
nd6_output_ifp(ifp, ifp, m,
(struct sockaddr_in6 *)&pd.pf_mtag->dst, NULL);
*m0 = NULL;
Expand All @@ -7510,11 +7527,10 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
/* Dummynet re-injects packets after they've
* completed their delay. We've already
* processed them, so pass unconditionally. */
PF_RULES_RUNLOCK();
return (PF_PASS);
}

PF_RULES_RLOCK();

/* We do IP header normalization and packet reassembly here */
if (pf_normalize_ip6(m0, dir, kif, &reason, &pd) != PF_PASS) {
action = PF_DROP;
Expand Down
16 changes: 16 additions & 0 deletions sys/nfs/bootp_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ bootpc_init(void)
struct thread *td;
int timeout;
int delay;
char *s;

timeout = BOOTP_IFACE_WAIT_TIMEOUT * hz;
delay = hz / 10;
Expand All @@ -1527,6 +1528,21 @@ bootpc_init(void)
if (nfs_diskless_valid != 0)
return;

/*
* If "vfs.root.mountfrom" is set and the value is something other
* than "nfs:", it means the user doesn't want to mount root via nfs,
* there's no reason to continue with bootpc
*/
if ((s = kern_getenv("vfs.root.mountfrom")) != NULL) {
if ((strncmp(s, "nfs:", 4)) != 0) {
printf("%s: vfs.root.mountfrom set to %s. "
"BOOTP aborted.\n", __func__, s);
freeenv(s);
return;
}
freeenv(s);
}

gctx = malloc(sizeof(*gctx), M_TEMP, M_WAITOK | M_ZERO);
STAILQ_INIT(&gctx->interfaces);
gctx->xid = ~0xFFFF;
Expand Down
2 changes: 2 additions & 0 deletions usr.bin/netstat/inet6.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
"{N:/bad checksum%s}\n");
p(icp6s_badlen, "\t{:dropped-bad-length/%ju} "
"{N:/message%s with bad length}\n");
p(icp6s_dropped, "{:dropped-no-entry/%ju} "
"{N:/total packet%s dropped due to failed NDP resolution}\n");
#define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
for (first = 1, i = 0; i < NELEM; i++)
if (icmp6stat.icp6s_inhist[i] != 0) {
Expand Down

0 comments on commit 9802f5e

Please sign in to comment.