Commit eaf7208e authored by HardenedBSD Sync Service's avatar HardenedBSD Sync Service
Browse files

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

parents f4ea9e17 ad15eeea
......@@ -3,8 +3,10 @@
*.a
*.core
*.o
*.orig
*.rej
*.so
*.swp
*.sw[nop]
*~
_.tinderbox.*
_.universe-toolchain
......
......@@ -126,11 +126,6 @@ vlan_parse_ethervid(const char *name)
strlcpy(ifname, name, IFNAMSIZ);
if ((cp = strrchr(ifname, '.')) == NULL)
return;
/*
* Don't mix vlan/vlandev parameters with dot notation.
*/
if (params.vlr_tag != NOTAG || params.vlr_parent[0] != '\0')
errx(1, "ambiguous vlan specification");
/*
* Derive params from interface name: "parent.vid".
*/
......@@ -144,8 +139,20 @@ vlan_parse_ethervid(const char *name)
if ((*cp != '\0') || (vid & ~0xFFF))
errx(1, "invalid vlan tag");
strlcpy(params.vlr_parent, ifname, IFNAMSIZ);
params.vlr_tag = (vid & 0xFFF);
/*
* allow "devX.Y vlandev devX vlan Y" syntax
*/
if (params.vlr_tag == NOTAG || params.vlr_tag == vid)
params.vlr_tag = vid;
else
errx(1, "ambiguous vlan specification");
/* Restrict overriding interface name */
if (params.vlr_parent[0] == '\0' || !strcmp(params.vlr_parent, ifname))
strlcpy(params.vlr_parent, ifname, IFNAMSIZ);
else
errx(1, "ambiguous vlan specification");
printf("CR: %s %d\n", params.vlr_parent, params.vlr_tag);
}
static void
......
......@@ -132,7 +132,7 @@ VSTATUS setting.
From a user perspective, this makes
.Va SIGINFO
work for Linux executables.
Defaults to 0.
Defaults to 1.
.It Va compat.linux.setid_allowed
Enable handling of set-user-ID and set-group-ID mode bits for the new
process image file when image is to be executed under Linux ABI.
......
......@@ -1412,11 +1412,6 @@ linprocfs_doprocmem(PFS_FILL_ARGS)
return (error);
}
/*
* Criteria for interface name translation
*/
#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
static int
linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
{
......@@ -1426,7 +1421,7 @@ linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
IFNET_RLOCK_ASSERT();
/* Short-circuit non ethernet interfaces */
if (!IFP_IS_ETH(ifp))
if (linux_use_real_ifname(ifp))
return (strlcpy(buffer, ifp->if_xname, buflen));
/* Determine the (relative) unit number for ethernet interfaces */
......@@ -1434,7 +1429,7 @@ linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
CK_STAILQ_FOREACH(ifscan, &V_ifnet, if_link) {
if (ifscan == ifp)
return (snprintf(buffer, buflen, "eth%d", ethno));
if (IFP_IS_ETH(ifscan))
if (!linux_use_real_ifname(ifscan))
ethno++;
}
......
......@@ -55,12 +55,6 @@
#define LINUX_IFHWADDRLEN 6
#define LINUX_IFNAMSIZ 16
/*
* Criteria for interface name translation
*/
#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
#define IFP_IS_LOOP(ifp) (ifp->if_type == IFT_LOOP)
struct l_sockaddr {
unsigned short sa_family;
char sa_data[14];
......
......@@ -2121,7 +2121,7 @@ linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr)
error = ENODEV;
CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
if (ifr.ifr_ifindex == index) {
if (IFP_IS_ETH(ifp))
if (!linux_use_real_ifname(ifp))
snprintf(ifr.ifr_name, LINUX_IFNAMSIZ,
"eth%d", ethno);
else
......@@ -2130,7 +2130,7 @@ linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr)
error = 0;
break;
}
if (IFP_IS_ETH(ifp))
if (!linux_use_real_ifname(ifp))
ethno++;
index++;
}
......
......@@ -86,7 +86,7 @@ int linux_ignore_ip_recverr = 1;
SYSCTL_INT(_compat_linux, OID_AUTO, ignore_ip_recverr, CTLFLAG_RWTUN,
&linux_ignore_ip_recverr, 0, "Ignore enabling IP_RECVERR");
int linux_preserve_vstatus = 0;
int linux_preserve_vstatus = 1;
SYSCTL_INT(_compat_linux, OID_AUTO, preserve_vstatus, CTLFLAG_RWTUN,
&linux_preserve_vstatus, 0, "Preserve VSTATUS termios(4) flag");
......
......@@ -1538,6 +1538,12 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
if (error != 0)
return (error);
/*
* Pass user-supplied recvmsg() flags in msg_flags field,
* following sys_recvmsg() convention.
*/
linux_msghdr.msg_flags = flags;
error = linux_to_bsd_msghdr(msg, &linux_msghdr);
if (error != 0)
return (error);
......
......@@ -50,6 +50,10 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/vnode.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_types.h>
#include <machine/stdarg.h>
#include <compat/linux/linux_dtrace.h>
......@@ -82,6 +86,11 @@ SYSCTL_STRING(_compat_linux, OID_AUTO, emul_path, CTLFLAG_RWTUN,
linux_emul_path, sizeof(linux_emul_path),
"Linux runtime environment path");
static bool use_real_ifnames = false;
SYSCTL_BOOL(_compat_linux, OID_AUTO, use_real_ifnames, CTLFLAG_RWTUN,
&use_real_ifnames, 0,
"Use FreeBSD interface names instead of generating ethN aliases");
/*
* Search an alternate path before passing pathname arguments on to
* system calls. Useful for keeping a separate 'emulation tree'.
......@@ -315,3 +324,9 @@ linux_device_unregister_handler(struct linux_device_handler *d)
return (EINVAL);
}
bool
linux_use_real_ifname(const struct ifnet *ifp)
{
return (use_real_ifnames || !IFP_IS_ETH(ifp));
}
......@@ -120,6 +120,15 @@ int linux_vn_get_major_minor(const struct vnode *vn, int *major, int *minor);
char *linux_get_char_devices(void);
void linux_free_get_char_devices(char *string);
/*
* Criteria for interface name translation
*/
#define IFP_IS_ETH(ifp) ((ifp)->if_type == IFT_ETHER)
#define IFP_IS_LOOP(ifp) ((ifp)->if_type == IFT_LOOP)
struct ifnet;
bool linux_use_real_ifname(const struct ifnet *ifp);
#if defined(KTR)
#define KTR_LINUX KTR_SUBSYS
......
......@@ -11,6 +11,7 @@ EXPORT_SYMS=
EXPORT_SYMS+= linux_emul_path
EXPORT_SYMS+= linux_get_osname
EXPORT_SYMS+= linux_get_osrelease
EXPORT_SYMS+= linux_use_real_ifname
.if !defined(KERNBUILDDIR)
.warning Building Linuxulator outside of a kernel does not make sense
......
......@@ -107,6 +107,14 @@ static struct xen_ipi_handler xen_ipis[] =
};
#endif
/*
* Save previous (native) handler as a fallback. Xen < 4.7 doesn't support
* VCPUOP_send_nmi for HVM guests, and thus we need a fallback in that case:
*
* https://lists.freebsd.org/archives/freebsd-xen/2022-January/000032.html
*/
void (*native_ipi_vectored)(u_int, int);
/*------------------------------- Per-CPU Data -------------------------------*/
#ifdef SMP
DPCPU_DEFINE(xen_intr_handle_t, ipi_handle[nitems(xen_ipis)]);
......@@ -273,10 +281,11 @@ xen_pv_lapic_ipi_raw(register_t icrlo, u_int dest)
}
#define PCPU_ID_GET(id, field) (pcpu_find(id)->pc_##field)
static void
static int
send_nmi(int dest)
{
unsigned int cpu;
int rc = 0;
/*
* NMIs are not routed over event channels, and instead delivered as on
......@@ -286,24 +295,33 @@ send_nmi(int dest)
*/
switch(dest) {
case APIC_IPI_DEST_SELF:
HYPERVISOR_vcpu_op(VCPUOP_send_nmi, PCPU_GET(vcpu_id), NULL);
rc = HYPERVISOR_vcpu_op(VCPUOP_send_nmi, PCPU_GET(vcpu_id), NULL);
break;
case APIC_IPI_DEST_ALL:
CPU_FOREACH(cpu)
HYPERVISOR_vcpu_op(VCPUOP_send_nmi,
CPU_FOREACH(cpu) {
rc = HYPERVISOR_vcpu_op(VCPUOP_send_nmi,
PCPU_ID_GET(cpu, vcpu_id), NULL);
if (rc != 0)
break;
}
break;
case APIC_IPI_DEST_OTHERS:
CPU_FOREACH(cpu)
if (cpu != PCPU_GET(cpuid))
HYPERVISOR_vcpu_op(VCPUOP_send_nmi,
CPU_FOREACH(cpu) {
if (cpu != PCPU_GET(cpuid)) {
rc = HYPERVISOR_vcpu_op(VCPUOP_send_nmi,
PCPU_ID_GET(cpu, vcpu_id), NULL);
if (rc != 0)
break;
}
}
break;
default:
HYPERVISOR_vcpu_op(VCPUOP_send_nmi,
rc = HYPERVISOR_vcpu_op(VCPUOP_send_nmi,
PCPU_ID_GET(apic_cpuid(dest), vcpu_id), NULL);
break;
}
return rc;
}
#undef PCPU_ID_GET
......@@ -312,9 +330,21 @@ xen_pv_lapic_ipi_vectored(u_int vector, int dest)
{
xen_intr_handle_t *ipi_handle;
int ipi_idx, to_cpu, self;
static bool pvnmi = true;
if (vector >= IPI_NMI_FIRST) {
send_nmi(dest);
if (pvnmi) {
int rc = send_nmi(dest);
if (rc != 0) {
printf(
"Sending NMI using hypercall failed (%d) switching to APIC\n", rc);
pvnmi = false;
native_ipi_vectored(vector, dest);
}
} else
native_ipi_vectored(vector, dest);
return;
}
......@@ -580,8 +610,8 @@ xen_setup_cpus(void)
xen_cpu_ipi_init(i);
/* Set the xen pv ipi ops to replace the native ones */
if (xen_hvm_domain())
apic_ops.ipi_vectored = xen_pv_lapic_ipi_vectored;
native_ipi_vectored = apic_ops.ipi_vectored;
apic_ops.ipi_vectored = xen_pv_lapic_ipi_vectored;
}
/* Switch to using PV IPIs as soon as the vcpu_id is set. */
......
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