Commit 8783789e authored by HardenedBSD Sync Service's avatar HardenedBSD Sync Service
Browse files

Merge branch 'freebsd/current/main' into hardened/current/master

parents c0003c9e a8c4147e
......@@ -34,7 +34,7 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <unistd.h>
#include <sys/procdesc.h>
#include "libc_private.h"
#pragma weak pdfork
......
......@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#ifdef TCP_OFFLOAD
#include <sys/errno.h>
#include <sys/gsb_crc32.h>
#include <sys/kthread.h>
#include <sys/smp.h>
#include <sys/socket.h>
......@@ -299,6 +300,136 @@ do_rx_iscsi_data(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m
return (0);
}
static int
mbuf_crc32c_helper(void *arg, void *data, u_int len)
{
uint32_t *digestp = arg;
*digestp = calculate_crc32c(*digestp, data, len);
return (0);
}
static bool
parse_pdus(struct toepcb *toep, struct icl_cxgbei_conn *icc, struct sockbuf *sb)
{
struct iscsi_bhs bhs;
struct mbuf *m;
struct icl_pdu *ip;
u_int ahs_len, data_len, header_len, pdu_len, total_len;
uint32_t calc_digest, wire_digest;
total_len = sbused(sb);
CTR3(KTR_CXGBE, "%s: tid %u, %u bytes in so_rcv", __func__, toep->tid,
total_len);
m = sbcut_locked(sb, total_len);
KASSERT(m_length(m, NULL) == total_len,
("sbcut returned less data (%u vs %u)", total_len,
m_length(m, NULL)));
header_len = sizeof(struct iscsi_bhs);
if (icc->ic.ic_header_crc32c)
header_len += ISCSI_HEADER_DIGEST_SIZE;
for (;;) {
if (total_len < sizeof(struct iscsi_bhs)) {
ICL_WARN("truncated pre-offload PDU with len %u",
total_len);
m_freem(m);
return (false);
}
m_copydata(m, 0, sizeof(struct iscsi_bhs), (caddr_t)&bhs);
ahs_len = bhs.bhs_total_ahs_len * 4;
data_len = bhs.bhs_data_segment_len[0] << 16 |
bhs.bhs_data_segment_len[1] << 8 |
bhs.bhs_data_segment_len[0];
pdu_len = header_len + ahs_len + roundup2(data_len, 4);
if (icc->ic.ic_data_crc32c && data_len != 0)
pdu_len += ISCSI_DATA_DIGEST_SIZE;
if (total_len < pdu_len) {
ICL_WARN("truncated pre-offload PDU len %u vs %u",
total_len, pdu_len);
m_freem(m);
return (false);
}
if (ahs_len != 0) {
ICL_WARN("received pre-offload PDU with AHS");
m_freem(m);
return (false);
}
if (icc->ic.ic_header_crc32c) {
m_copydata(m, sizeof(struct iscsi_bhs),
sizeof(wire_digest), (caddr_t)&wire_digest);
calc_digest = calculate_crc32c(0xffffffff,
(caddr_t)&bhs, sizeof(bhs));
calc_digest ^= 0xffffffff;
if (calc_digest != wire_digest) {
ICL_WARN("received pre-offload PDU 0x%02x "
"with invalid header digest (0x%x vs 0x%x)",
bhs.bhs_opcode, wire_digest, calc_digest);
toep->ofld_rxq->rx_iscsi_header_digest_errors++;
m_free(m);
return (false);
}
}
m_adj(m, header_len);
if (icc->ic.ic_data_crc32c && data_len != 0) {
m_copydata(m, data_len, sizeof(wire_digest),
(caddr_t)&wire_digest);
calc_digest = 0xffffffff;
m_apply(m, 0, roundup2(data_len, 4), mbuf_crc32c_helper,
&calc_digest);
calc_digest ^= 0xffffffff;
if (calc_digest != wire_digest) {
ICL_WARN("received pre-offload PDU 0x%02x "
"with invalid data digest (0x%x vs 0x%x)",
bhs.bhs_opcode, wire_digest, calc_digest);
toep->ofld_rxq->rx_iscsi_data_digest_errors++;
m_free(m);
return (false);
}
}
ip = icl_cxgbei_new_pdu(M_NOWAIT);
if (ip == NULL)
CXGBE_UNIMPLEMENTED("PDU allocation failure");
icl_cxgbei_new_pdu_set_conn(ip, &icc->ic);
*ip->ip_bhs = bhs;
ip->ip_data_len = data_len;
if (data_len != 0)
ip->ip_data_mbuf = m;
STAILQ_INSERT_TAIL(&icc->rcvd_pdus, ip, ip_next);
total_len -= pdu_len;
if (total_len == 0) {
if (data_len == 0)
m_freem(m);
return (true);
}
if (data_len != 0) {
m = m_split(m, roundup2(data_len, 4), M_NOWAIT);
if (m == NULL) {
ICL_WARN("failed to split mbuf chain for "
"pre-offload PDU");
/* Don't free the mbuf chain as 'ip' owns it. */
return (false);
}
if (icc->ic.ic_data_crc32c)
m_adj(m, ISCSI_DATA_DIGEST_SIZE);
}
}
}
static int
do_rx_iscsi_ddp(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
{
......@@ -419,39 +550,24 @@ do_rx_iscsi_ddp(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
ic->ic_error(ic);
return (0);
}
icl_cxgbei_new_pdu_set_conn(ip, ic);
MPASS(m == NULL); /* was unused, we'll use it now. */
m = sbcut_locked(sb, sbused(sb)); /* XXXNP: toep->sb_cc accounting? */
if (__predict_false(m != NULL)) {
int len = m_length(m, NULL);
if (__predict_false(sbused(sb)) != 0) {
/*
* PDUs were received before the tid transitioned to ULP mode.
* Convert them to icl_cxgbei_pdus and send them to ICL before
* the PDU in icp/ip.
*/
CTR3(KTR_CXGBE, "%s: tid %u, %u bytes in so_rcv", __func__, tid,
len);
/* XXXNP: needs to be rewritten. */
if (len == sizeof(struct iscsi_bhs) || len == 4 + sizeof(struct
iscsi_bhs)) {
struct icl_cxgbei_pdu *icp0;
struct icl_pdu *ip0;
ip0 = icl_cxgbei_new_pdu(M_NOWAIT);
if (ip0 == NULL)
CXGBE_UNIMPLEMENTED("PDU allocation failure");
icl_cxgbei_new_pdu_set_conn(ip0, ic);
icp0 = ip_to_icp(ip0);
icp0->icp_seq = 0; /* XXX */
icp0->icp_flags = ICPF_RX_HDR | ICPF_RX_STATUS;
m_copydata(m, 0, sizeof(struct iscsi_bhs), (void *)ip0->ip_bhs);
STAILQ_INSERT_TAIL(&icc->rcvd_pdus, ip0, ip_next);
if (!parse_pdus(toep, icc, sb)) {
SOCKBUF_UNLOCK(sb);
INP_WUNLOCK(inp);
icl_cxgbei_conn_pdu_free(NULL, ip);
toep->ulpcb2 = NULL;
ic->ic_error(ic);
return (0);
}
m_freem(m);
}
icl_cxgbei_new_pdu_set_conn(ip, ic);
STAILQ_INSERT_TAIL(&icc->rcvd_pdus, ip, ip_next);
if ((icc->rx_flags & RXF_ACTIVE) == 0) {
......@@ -700,6 +816,23 @@ do_rx_iscsi_cmp(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
m_freem(m);
return (0);
}
if (__predict_false(sbused(sb)) != 0) {
/*
* PDUs were received before the tid transitioned to ULP mode.
* Convert them to icl_cxgbei_pdus and send them to ICL before
* the PDU in icp/ip.
*/
if (!parse_pdus(toep, icc, sb)) {
SOCKBUF_UNLOCK(sb);
INP_WUNLOCK(inp);
icl_cxgbei_conn_pdu_free(NULL, ip);
toep->ulpcb2 = NULL;
ic->ic_error(ic);
return (0);
}
}
icl_cxgbei_new_pdu_set_conn(ip, ic);
/* Enqueue the PDU to the received pdus queue. */
......
......@@ -820,8 +820,6 @@ mpr_attach_sas(struct mpr_softc *sc)
sc->sassc->startup_refcount = 0;
mprsas_startup_increment(sassc);
callout_init(&sassc->discovery_callout, 1 /*mpsafe*/);
mpr_unlock(sc);
/*
......@@ -937,9 +935,6 @@ mprsas_discovery_end(struct mprsas_softc *sassc)
MPR_FUNCTRACE(sc);
if (sassc->flags & MPRSAS_DISCOVERY_TIMEOUT_PENDING)
callout_stop(&sassc->discovery_callout);
/*
* After discovery has completed, check the mapping table for any
* missing devices and update their missing counts. Only do this once
......
......@@ -91,9 +91,7 @@ struct mprsas_softc {
u_int flags;
#define MPRSAS_IN_DISCOVERY (1 << 0)
#define MPRSAS_IN_STARTUP (1 << 1)
#define MPRSAS_DISCOVERY_TIMEOUT_PENDING (1 << 2)
#define MPRSAS_QUEUE_FROZEN (1 << 3)
#define MPRSAS_SHUTDOWN (1 << 4)
#define MPRSAS_TOREMOVE (1 << 5)
u_int maxtargets;
struct mprsas_target *targets;
......@@ -101,7 +99,6 @@ struct mprsas_softc {
struct cam_sim *sim;
struct cam_path *path;
struct intr_config_hook sas_ich;
struct callout discovery_callout;
struct mpr_event_handle *mprsas_eh;
u_int startup_refcount;
......
......@@ -86,9 +86,6 @@ __FBSDID("$FreeBSD$");
#include <dev/mps/mps_table.h>
#include <dev/mps/mps_sas.h>
#define MPSSAS_DISCOVERY_TIMEOUT 20
#define MPSSAS_MAX_DISCOVERY_TIMEOUTS 10 /* 200 seconds */
/*
* static array to check SCSI OpCode for EEDP protection bits
*/
......@@ -773,8 +770,6 @@ mps_attach_sas(struct mps_softc *sc)
sc->sassc->startup_refcount = 0;
mpssas_startup_increment(sassc);
callout_init(&sassc->discovery_callout, 1 /*mpsafe*/);
mps_unlock(sc);
/*
......@@ -889,9 +884,6 @@ mpssas_discovery_end(struct mpssas_softc *sassc)
MPS_FUNCTRACE(sc);
if (sassc->flags & MPSSAS_DISCOVERY_TIMEOUT_PENDING)
callout_stop(&sassc->discovery_callout);
/*
* After discovery has completed, check the mapping table for any
* missing devices and update their missing counts. Only do this once
......
......@@ -86,16 +86,13 @@ struct mpssas_softc {
u_int flags;
#define MPSSAS_IN_DISCOVERY (1 << 0)
#define MPSSAS_IN_STARTUP (1 << 1)
#define MPSSAS_DISCOVERY_TIMEOUT_PENDING (1 << 2)
#define MPSSAS_QUEUE_FROZEN (1 << 3)
#define MPSSAS_SHUTDOWN (1 << 4)
u_int maxtargets;
struct mpssas_target *targets;
struct cam_devq *devq;
struct cam_sim *sim;
struct cam_path *path;
struct intr_config_hook sas_ich;
struct callout discovery_callout;
struct mps_event_handle *mpssas_eh;
u_int startup_refcount;
......
......@@ -1419,7 +1419,7 @@ ogetsockname(struct thread *td, struct ogetsockname_args *uap)
static int
user_getpeername(struct thread *td, int fdes, struct sockaddr *asa,
socklen_t *alen, int compat)
socklen_t *alen, bool compat)
{
struct sockaddr *sa;
socklen_t len;
......@@ -1493,14 +1493,14 @@ kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
int
sys_getpeername(struct thread *td, struct getpeername_args *uap)
{
return (user_getpeername(td, uap->fdes, uap->asa, uap->alen, 0));
return (user_getpeername(td, uap->fdes, uap->asa, uap->alen, false));
}
#ifdef COMPAT_OLDSOCK
int
ogetpeername(struct thread *td, struct ogetpeername_args *uap)
{
return (user_getpeername(td, uap->fdes, uap->asa, uap->alen, 1));
return (user_getpeername(td, uap->fdes, uap->asa, uap->alen, true));
}
#endif /* COMPAT_OLDSOCK */
......
......@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
#
# Copyright (c) September 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
# Copyright (c) September 1995-2022 Wolfram Schneider <wosch@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
......@@ -30,19 +30,19 @@
#
# usage: concatdb database1 ... databaseN > newdb
#
# Sequence of databases is important.
# Please note: the sequence of databases is important.
#
# $FreeBSD$
# stop on first error
set -e
set -o pipefail
# The directory containing locate subprograms
: ${LIBEXECDIR:=/usr/libexec}; export LIBEXECDIR
PATH=$LIBEXECDIR:/bin:/usr/bin:$PATH; export PATH
umask 077 # protect temp files
: ${TMPDIR:=/var/tmp}; export TMPDIR;
test -d "$TMPDIR" || TMPDIR=/var/tmp
# utilities to built locate database
: ${bigram:=locate.bigram}
......@@ -50,23 +50,23 @@ test -d "$TMPDIR" || TMPDIR=/var/tmp
: ${sort:=sort}
: ${locate:=locate}
if [ $# -lt 2 ]; then
echo 'usage: concatdb databases1 ... databaseN > newdb'
exit 1
fi
case $# in
[01]) echo 'usage: concatdb databases1 ... databaseN > newdb'
exit 1
;;
esac
bigrams=`mktemp ${TMPDIR=/tmp}/_bigrams.XXXXXXXXXX` || exit 1
bigrams=$(mktemp -t bigrams)
trap 'rm -f $bigrams' 0 1 2 3 5 10 15
for db
do
$locate -d $db /
done | $bigram | $sort -nr | awk 'NR <= 128 { printf $2 }' > $bigrams
done | $bigram | $sort -nr | \
awk 'NR <= 128 && /^[ \t]*[1-9][0-9]*[ \t]+..$/ { printf("%s", substr($0, length($0)-1, 2)) }' > $bigrams
for db
do
$locate -d $db /
done | $code $bigrams
#EOF
......@@ -2865,7 +2865,7 @@ main(int argc, char **argv)
argv[0]);
printf("-i inputfile -- use source as inputfile not stdin (if stdin collect)\n");
printf("-v -- verbose dump debug type things -- you don't want this\n");
printf("-m N -- maximum to collect is N measurments\n");
printf("-m N -- maximum to collect is N measurements\n");
printf("-e expr-name -- Do expression expr-name\n");
printf("-E 'your expression' -- Do your expression\n");
printf("-h -- Don't do the expression I put in -e xxx just explain what it does and exit\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment