sync code with last fixes and improvements from OpenBSD

This commit is contained in:
purplerain 2023-05-14 12:20:04 +00:00
parent 62073e0295
commit 0f55503fed
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
72 changed files with 797 additions and 1127 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
**/obj
**/tags

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: sh.1,v 1.156 2022/12/19 08:19:50 sdk Exp $
.\" $OpenBSD: sh.1,v 1.157 2023/05/13 18:34:49 jmc Exp $
.\"
.\" Copyright (c) 2015 Jason McIntyre <jmc@openbsd.org>
.\"
@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: December 19 2022 $
.Dd $Mdocdate: May 13 2023 $
.Dt SH 1
.Os
.Sh NAME
@ -2108,7 +2108,7 @@ on
.Ox
is:
.Bd -literal -offset 2n
/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
.Ed
.It Ev POSIXLY_CORRECT
Enable POSIX mode

View File

@ -1,4 +1,4 @@
/* Definitions of target machine for GNU compiler, OpenBSD/arm ELF version.
/* Definitions of target machine for GNU compiler, SecBSD/arm ELF version.
Copyright (C) 2002 Free Software Foundation, Inc.
Contributed by Wasabi Systems, Inc.
@ -21,11 +21,11 @@ Boston, MA 02111-1307, USA. */
/* Run-time Target Specification. */
#undef TARGET_VERSION
#define TARGET_VERSION fputs (" (OpenBSD/arm)", stderr);
#define TARGET_VERSION fputs (" (SecBSD/arm)", stderr);
/* This is used in ASM_FILE_START. */
#undef ARM_OS_NAME
#define ARM_OS_NAME "OpenBSD"
#define ARM_OS_NAME "SecBSD"
/* Unsigned chars produces much better code than signed. */
#define DEFAULT_SIGNED_CHAR 0
@ -55,21 +55,21 @@ Boston, MA 02111-1307, USA. */
do \
{ \
builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \
OPENBSD_OS_CPP_BUILTINS_ELF(); \
SECBSD_OS_CPP_BUILTINS_ELF(); \
} \
while (0)
#undef SUBTARGET_CPP_SPEC
#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC
#define SUBTARGET_CPP_SPEC SBSD_CPP_SPEC
/* OBSD_LINK_SPEC appropriate for OpenBSD. Support for GCC options
/* SBSD_LINK_SPEC appropriate for SecBSD. Support for GCC options
-static, -assert, and -nostdlib. */
#undef OBSD_LINK_SPEC
#ifdef OBSD_NO_DYNAMIC_LIBRARIES
#define OBSD_LINK_SPEC \
#undef SBSD_LINK_SPEC
#ifdef SBSD_NO_DYNAMIC_LIBRARIES
#define SBSD_LINK_SPEC \
"%{!nostdlib:%{!r*:%{!e*:-e __start}}} %{assert*}"
#else
#define OBSD_LINK_SPEC \
#define SBSD_LINK_SPEC \
"%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \
%{shared:-shared} %{R*} \
%{static:-Bstatic} \
@ -97,10 +97,10 @@ Boston, MA 02111-1307, USA. */
#define SUBTARGET_EXTRA_SPECS \
{ "subtarget_extra_asm_spec", SUBTARGET_EXTRA_ASM_SPEC }, \
{ "subtarget_asm_float_spec", SUBTARGET_ASM_FLOAT_SPEC }, \
{ "openbsd_link_spec", OBSD_LINK_SPEC }, \
{ "openbsd_entry_point", OPENBSD_ENTRY_POINT },
{ "openbsd_link_spec", SBSD_LINK_SPEC }, \
{ "openbsd_entry_point", SECBSD_ENTRY_POINT },
#define OPENBSD_ENTRY_POINT "__start"
#define SECBSD_ENTRY_POINT "__start"
/* Pass -X to the linker so that it will strip symbols starting with 'L' */
#undef LINK_SPEC
@ -131,7 +131,7 @@ Boston, MA 02111-1307, USA. */
/* We don't have any limit on the length as out debugger is GDB. */
#undef DBX_CONTIN_LENGTH
/* OpenBSD and NetBSD do their profiling differently to the Acorn compiler. We
/* SecBSD and NetBSD do their profiling differently to the Acorn compiler. We
don't need a word following the mcount call; and to skip it
requires either an assembly stub or use of fomit-frame-pointer when
compiling the profiling functions. Since we break Acorn CC
@ -153,12 +153,12 @@ Boston, MA 02111-1307, USA. */
#undef FPUTYPE_DEFAULT
#define FPUTYPE_DEFAULT FPUTYPE_VFP
/* VERY BIG NOTE: Change of structure alignment for OpenBSD|NetBSD/arm.
/* VERY BIG NOTE: Change of structure alignment for SecBSD|NetBSD/arm.
There are consequences you should be aware of...
Normally GCC/arm uses a structure alignment of 32 for compatibility
with armcc. This means that structures are padded to a word
boundary. However this causes problems with bugged OpenBSD|NetBSD kernel
boundary. However this causes problems with bugged SecBSD|NetBSD kernel
code (possibly userland code as well - I have not checked every
binary). The nature of this bugged code is to rely on sizeof()
returning the correct size of various structures rounded to the
@ -166,7 +166,7 @@ Boston, MA 02111-1307, USA. */
is another). This code breaks when the structure alignment is 32
as sizeof() will report a word=rounded size. By changing the
structure alignment to 8. GCC will conform to what is expected by
OpenBSD|NetBSD.
SecBSD|NetBSD.
This has several side effects that should be considered.
1. Structures will only be aligned to the size of the largest member.
@ -182,7 +182,7 @@ Boston, MA 02111-1307, USA. */
short strings.
This modification is not encouraged but with the present state of the
OpenBSD|NetBSD source tree it is currently the only solution that meets the
SecBSD|NetBSD source tree it is currently the only solution that meets the
requirements. */
#undef DEFAULT_STRUCTURE_SIZE_BOUNDARY

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: execv.3,v 1.1 2019/08/11 15:48:08 deraadt Exp $
.\" $OpenBSD: execv.3,v 1.2 2023/05/13 16:36:40 kn Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: August 11 2019 $
.Dd $Mdocdate: May 13 2023 $
.Dt EXECV 3
.Os
.Sh NAME
@ -136,8 +136,14 @@ If this variable isn't specified,
.Dv _PATH_DEFPATH
from
.In paths.h
is used instead, its value being:
.Pa /usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
is used instead, consisting of
.Pa /usr/bin ,
.Pa /bin ,
.Pa /usr/sbin ,
.Pa /sbin ,
.Pa /usr/X11R6/bin ,
.Pa /usr/local/bin ,
.Pa /usr/local/sbin .
.Pp
In addition, certain errors are treated specially.
.Pp
@ -201,7 +207,9 @@ Historically, the default path for the
and
.Fn execvp
functions was
.Pa \&.:/bin:/usr/bin .
.Pa \&. ,
.Pa /bin ,
.Pa /usr/bin .
This was changed to improve security and behaviour.
.Pp
The behavior of

View File

@ -1,377 +0,0 @@
/* $OpenBSD: bf_lbuf.c,v 1.15 2022/01/14 08:40:57 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <errno.h>
#include <stdio.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
static int linebuffer_write(BIO *h, const char *buf, int num);
static int linebuffer_read(BIO *h, char *buf, int size);
static int linebuffer_puts(BIO *h, const char *str);
static int linebuffer_gets(BIO *h, char *str, int size);
static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int linebuffer_new(BIO *h);
static int linebuffer_free(BIO *data);
static long linebuffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
/* A 10k maximum should be enough for most purposes */
#define DEFAULT_LINEBUFFER_SIZE 1024*10
/* #define DEBUG */
static BIO_METHOD methods_linebuffer = {
.type = BIO_TYPE_LINEBUFFER,
.name = "linebuffer",
.bwrite = linebuffer_write,
.bread = linebuffer_read,
.bputs = linebuffer_puts,
.bgets = linebuffer_gets,
.ctrl = linebuffer_ctrl,
.create = linebuffer_new,
.destroy = linebuffer_free,
.callback_ctrl = linebuffer_callback_ctrl
};
BIO_METHOD *
BIO_f_linebuffer(void)
{
return (&methods_linebuffer);
}
typedef struct bio_linebuffer_ctx_struct {
char *obuf; /* the output char array */
int obuf_size; /* how big is the output buffer */
int obuf_len; /* how many bytes are in it */
} BIO_LINEBUFFER_CTX;
static int
linebuffer_new(BIO *bi)
{
BIO_LINEBUFFER_CTX *ctx;
ctx = malloc(sizeof(BIO_LINEBUFFER_CTX));
if (ctx == NULL)
return (0);
ctx->obuf = malloc(DEFAULT_LINEBUFFER_SIZE);
if (ctx->obuf == NULL) {
free(ctx);
return (0);
}
ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE;
ctx->obuf_len = 0;
bi->init = 1;
bi->ptr = (char *)ctx;
bi->flags = 0;
return (1);
}
static int
linebuffer_free(BIO *a)
{
BIO_LINEBUFFER_CTX *b;
if (a == NULL)
return (0);
b = (BIO_LINEBUFFER_CTX *)a->ptr;
free(b->obuf);
free(a->ptr);
a->ptr = NULL;
a->init = 0;
a->flags = 0;
return (1);
}
static int
linebuffer_read(BIO *b, char *out, int outl)
{
int ret = 0;
if (out == NULL)
return (0);
if (b->next_bio == NULL)
return (0);
ret = BIO_read(b->next_bio, out, outl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
return (ret);
}
static int
linebuffer_write(BIO *b, const char *in, int inl)
{
int i, num = 0, foundnl;
BIO_LINEBUFFER_CTX *ctx;
if ((in == NULL) || (inl <= 0))
return (0);
ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
if ((ctx == NULL) || (b->next_bio == NULL))
return (0);
BIO_clear_retry_flags(b);
do {
const char *p;
for (p = in; p < in + inl && *p != '\n'; p++)
;
if (*p == '\n') {
p++;
foundnl = 1;
} else
foundnl = 0;
/* If a NL was found and we already have text in the save
buffer, concatenate them and write */
while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) &&
ctx->obuf_len > 0) {
int orig_olen = ctx->obuf_len;
i = ctx->obuf_size - ctx->obuf_len;
if (p - in > 0) {
if (i >= p - in) {
memcpy(&(ctx->obuf[ctx->obuf_len]),
in, p - in);
ctx->obuf_len += p - in;
inl -= p - in;
num += p - in;
in = p;
} else {
memcpy(&(ctx->obuf[ctx->obuf_len]),
in, i);
ctx->obuf_len += i;
inl -= i;
in += i;
num += i;
}
}
i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
if (i <= 0) {
ctx->obuf_len = orig_olen;
BIO_copy_next_retry(b);
if (i < 0)
return ((num > 0) ? num : i);
if (i == 0)
return (num);
}
if (i < ctx->obuf_len)
memmove(ctx->obuf, ctx->obuf + i,
ctx->obuf_len - i);
ctx->obuf_len -= i;
}
/* Now that the save buffer is emptied, let's write the input
buffer if a NL was found and there is anything to write. */
if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) {
i = BIO_write(b->next_bio, in, p - in);
if (i <= 0) {
BIO_copy_next_retry(b);
if (i < 0)
return ((num > 0) ? num : i);
if (i == 0)
return (num);
}
num += i;
in += i;
inl -= i;
}
} while (foundnl && inl > 0);
/* We've written as much as we can. The rest of the input buffer, if
any, is text that doesn't and with a NL and therefore needs to be
saved for the next trip. */
if (inl > 0) {
memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
ctx->obuf_len += inl;
num += inl;
}
return num;
}
static long
linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
{
BIO *dbio;
BIO_LINEBUFFER_CTX *ctx;
long ret = 1;
char *p;
int r;
int obs;
ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
switch (cmd) {
case BIO_CTRL_RESET:
ctx->obuf_len = 0;
if (b->next_bio == NULL)
return (0);
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_INFO:
ret = (long)ctx->obuf_len;
break;
case BIO_CTRL_WPENDING:
ret = (long)ctx->obuf_len;
if (ret == 0) {
if (b->next_bio == NULL)
return (0);
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
}
break;
case BIO_C_SET_BUFF_SIZE:
obs = (int)num;
p = ctx->obuf;
if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
p = malloc(num);
if (p == NULL)
goto malloc_error;
}
if (ctx->obuf != p) {
if (ctx->obuf_len > obs) {
ctx->obuf_len = obs;
}
memcpy(p, ctx->obuf, ctx->obuf_len);
free(ctx->obuf);
ctx->obuf = p;
ctx->obuf_size = obs;
}
break;
case BIO_C_DO_STATE_MACHINE:
if (b->next_bio == NULL)
return (0);
BIO_clear_retry_flags(b);
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_FLUSH:
if (b->next_bio == NULL)
return (0);
if (ctx->obuf_len <= 0) {
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
}
for (;;) {
BIO_clear_retry_flags(b);
if (ctx->obuf_len > 0) {
r = BIO_write(b->next_bio,
ctx->obuf, ctx->obuf_len);
BIO_copy_next_retry(b);
if (r <= 0)
return ((long)r);
if (r < ctx->obuf_len)
memmove(ctx->obuf, ctx->obuf + r,
ctx->obuf_len - r);
ctx->obuf_len -= r;
} else {
ctx->obuf_len = 0;
ret = 1;
break;
}
}
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_DUP:
dbio = (BIO *)ptr;
if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size))
ret = 0;
break;
default:
if (b->next_bio == NULL)
return (0);
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
}
return (ret);
malloc_error:
BIOerror(ERR_R_MALLOC_FAILURE);
return (0);
}
static long
linebuffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
{
long ret = 1;
if (b->next_bio == NULL)
return (0);
switch (cmd) {
default:
ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
}
return (ret);
}
static int
linebuffer_gets(BIO *b, char *buf, int size)
{
if (b->next_bio == NULL)
return (0);
return (BIO_gets(b->next_bio, buf, size));
}
static int
linebuffer_puts(BIO *b, const char *str)
{
return (linebuffer_write(b, str, strlen(str)));
}

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: DSA_generate_parameters.3,v 1.12 2019/06/10 14:58:48 schwarze Exp $
.\" $OpenBSD: DSA_generate_parameters.3,v 1.13 2023/05/14 09:27:15 tb Exp $
.\" OpenSSL 9b86974e Aug 7 22:14:47 2015 -0400
.\"
.\" This file was written by Ulf Moeller <ulf@openssl.org>,
@ -49,7 +49,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: June 10 2019 $
.Dd $Mdocdate: May 14 2023 $
.Dt DSA_GENERATE_PARAMETERS 3
.Os
.Sh NAME
@ -216,7 +216,7 @@ reached the squaring step (the parameters to
did not reveal how many witnesses had been tested); since OpenSSL 0.9.5,
.Fn callback 1 ...\&
is called as in
.Xr BN_is_prime 3 ,
.Xr BN_is_prime_ex 3 ,
i.e. once for each witness.
.Pp
.Fn DSA_generate_parameters_ex

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: EVP_PKEY_encrypt.3,v 1.7 2022/03/31 17:27:17 naddy Exp $
.\" $OpenBSD: EVP_PKEY_encrypt.3,v 1.8 2023/05/14 09:29:37 tb Exp $
.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
.\"
.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
@ -49,7 +49,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 31 2022 $
.Dd $Mdocdate: May 14 2023 $
.Dt EVP_PKEY_ENCRYPT 3
.Os
.Sh NAME
@ -131,7 +131,9 @@ and
.Xr d2i_X509 3
for means to load a public key.
You may also simply set
.Ql eng = NULL;
.Dq eng
to
.Dv NULL
to start with the default OpenSSL RSA implementation:
.Bd -literal -offset indent
#include <openssl/evp.h>

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: POLICYINFO_new.3,v 1.9 2021/10/27 11:24:47 schwarze Exp $
.\" $OpenBSD: POLICYINFO_new.3,v 1.11 2023/05/14 08:03:57 tb Exp $
.\"
.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
.\"
@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: October 27 2021 $
.Dd $Mdocdate: May 14 2023 $
.Dt POLICYINFO_NEW 3
.Os
.Sh NAME
@ -179,8 +179,7 @@ if an error occurs.
.Xr NAME_CONSTRAINTS_new 3 ,
.Xr X509_EXTENSION_new 3 ,
.Xr X509_get_extension_flags 3 ,
.Xr X509_new 3 ,
.Xr X509_policy_tree_level_count 3
.Xr X509_new 3
.Sh STANDARDS
RFC 5280: Internet X.509 Public Key Infrastructure Certificate and
Certificate Revocation List (CRL) Profile:

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: RSA_set_method.3,v 1.16 2022/01/15 23:38:50 jsg Exp $
.\" $OpenBSD: RSA_set_method.3,v 1.17 2023/05/14 09:33:19 tb Exp $
.\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
.\"
.\" This file was written by Ulf Moeller <ulf@openssl.org>
@ -50,7 +50,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: January 15 2022 $
.Dd $Mdocdate: May 14 2023 $
.Dt RSA_SET_METHOD 3
.Os
.Sh NAME
@ -274,5 +274,7 @@ but will not be reflected in the return value of the
.Fn RSA_flags
function - in effect
.Fn RSA_flags
behaves more like an RSA_default_flags() function, which does not
behaves more like an
.Fn RSA_default_flags
function, which does not
currently exist.

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x509_err.c,v 1.21 2023/04/24 08:39:06 job Exp $ */
/* $OpenBSD: x509_err.c,v 1.22 2023/05/14 17:20:26 tb Exp $ */
/* ====================================================================
* Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
*
@ -71,11 +71,6 @@ static ERR_STRING_DATA X509_str_functs[] = {
{0, NULL}
};
static ERR_STRING_DATA X509V3_str_functs[] = {
{ERR_FUNC(0xfff), "CRYPTO_internal"},
{0, NULL}
};
static ERR_STRING_DATA X509_str_reasons[] = {
{ERR_REASON(X509_R_BAD_X509_FILETYPE) , "bad x509 filetype"},
{ERR_REASON(X509_R_BASE64_DECODE_ERROR) , "base64 decode error"},
@ -108,6 +103,16 @@ static ERR_STRING_DATA X509_str_reasons[] = {
{0, NULL}
};
#undef ERR_FUNC
#undef ERR_REASON
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509V3,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509V3,0,reason)
static ERR_STRING_DATA X509V3_str_functs[] = {
{ERR_FUNC(0xfff), "CRYPTO_internal"},
{0, NULL}
};
static ERR_STRING_DATA X509V3_str_reasons[] = {
{ERR_REASON(X509V3_R_BAD_IP_ADDRESS) , "bad ip address"},
{ERR_REASON(X509V3_R_BAD_OBJECT) , "bad object"},

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls.c,v 1.94 2022/02/08 19:13:50 tb Exp $ */
/* $OpenBSD: tls.c,v 1.95 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@ -21,6 +21,7 @@
#include <limits.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/bio.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_bio_cb.c,v 1.20 2022/01/10 23:39:48 tb Exp $ */
/* $OpenBSD: tls_bio_cb.c,v 1.21 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2016 Tobias Pape <tobias@netshed.de>
*
@ -17,6 +17,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/bio.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_client.c,v 1.48 2021/10/21 08:38:11 tb Exp $ */
/* $OpenBSD: tls_client.c,v 1.49 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@ -25,6 +25,7 @@
#include <limits.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/err.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_config.c,v 1.65 2022/01/25 21:51:24 eric Exp $ */
/* $OpenBSD: tls_config.c,v 1.66 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@ -22,6 +22,7 @@
#include <fcntl.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <tls.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_conninfo.c,v 1.22 2021/01/05 15:57:38 tb Exp $ */
/* $OpenBSD: tls_conninfo.c,v 1.23 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2015 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2015 Bob Beck <beck@openbsd.org>
@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include <string.h>
#include <openssl/x509.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_ocsp.c,v 1.22 2021/10/31 16:39:32 tb Exp $ */
/* $OpenBSD: tls_ocsp.c,v 1.23 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2015 Marko Kreen <markokr@gmail.com>
* Copyright (c) 2016 Bob Beck <beck@openbsd.org>
@ -21,6 +21,8 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <openssl/err.h>
#include <openssl/ocsp.h>
#include <openssl/x509.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_server.c,v 1.48 2022/01/19 11:10:55 inoguchi Exp $ */
/* $OpenBSD: tls_server.c,v 1.49 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@ -19,6 +19,8 @@
#include <arpa/inet.h>
#include <string.h>
#include <openssl/ec.h>
#include <openssl/err.h>
#include <openssl/ssl.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls_util.c,v 1.15 2021/08/16 13:54:38 tb Exp $ */
/* $OpenBSD: tls_util.c,v 1.16 2023/05/14 07:26:25 op Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
@ -20,6 +20,7 @@
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn1oct.c,v 1.3 2023/05/12 10:43:28 tb Exp $ */
/* $OpenBSD: asn1oct.c,v 1.4 2023/05/13 07:17:32 tb Exp $ */
/*
* Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
@ -16,6 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <assert.h>
#include <err.h>
#include <string.h>
@ -239,6 +240,7 @@ test_s2i_ASN1_OCTET_STRING(const struct s2i_asn1_octet_string_test *test)
if ((got = i2s_ASN1_OCTET_STRING(NULL, aos)) == NULL)
errx(1, "%s: i2s_ASN1_OCTET_STRING", test->desc);
assert(test->want != NULL);
if (strcmp(test->want, got) != 0) {
fprintf(stderr, "%s: \"%s\" failed: want \"%s\", got \"%s\"\n",
__func__, test->desc, test->want, got);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vcpu.c,v 1.5 2023/04/27 05:42:44 anton Exp $ */
/* $OpenBSD: vcpu.c,v 1.6 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2022 Dave Voutila <dv@openbsd.org>
@ -83,6 +83,7 @@ main(int argc, char **argv)
struct vm_resetcpu_params vresetp;
struct vm_run_params vrunp;
struct vm_terminate_params vtp;
struct vm_sharemem_params vsp;
struct vm_mem_range *vmr;
int fd, ret = 1;
@ -127,8 +128,9 @@ main(int argc, char **argv)
((uint8_t*)p)[j + 1] = PCKBC_AUX;
}
vmr->vmr_va = (vaddr_t)p;
printf("mapped region %zu: { gpa: 0x%08lx, size: %lu }\n",
i, vmr->vmr_gpa, vmr->vmr_size);
printf("created mapped region %zu: { gpa: 0x%08lx, size: %lu,"
" hva: 0x%lx }\n", i, vmr->vmr_gpa, vmr->vmr_size,
vmr->vmr_va);
}
if (ioctl(fd, VMM_IOC_CREATE, &vcp) == -1)
@ -136,7 +138,54 @@ main(int argc, char **argv)
printf("created vm %d named \"%s\"\n", vcp.vcp_id, vcp.vcp_name);
/*
* 2. Check that our VM exists.
* 2. Check we can create shared memory mappings.
*/
memset(&vsp, 0, sizeof(vsp));
vsp.vsp_nmemranges = vcp.vcp_nmemranges;
memcpy(&vsp.vsp_memranges, &vcp.vcp_memranges,
sizeof(vsp.vsp_memranges));
vsp.vsp_vm_id = vcp.vcp_id;
/* Find some new va ranges... */
for (i = 0; i < vsp.vsp_nmemranges; i++) {
vmr = &vsp.vsp_memranges[i];
p = mmap(NULL, vmr->vmr_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (p == MAP_FAILED)
err(1, "mmap");
vmr->vmr_va = (vaddr_t)p;
}
/* Release our mappings so vmm can replace them. */
for (i = 0; i < vsp.vsp_nmemranges; i++) {
vmr = &vsp.vsp_memranges[i];
munmap((void*)vmr->vmr_va, vmr->vmr_size);
}
/* Perform the shared mapping. */
if (ioctl(fd, VMM_IOC_SHAREMEM, &vsp) == -1)
err(1, "VMM_IOC_SHAREMEM");
printf("created shared memory mappings\n");
/* We should see our reset vector instructions in the new mappings. */
for (i = 0; i < vsp.vsp_nmemranges; i++) {
vmr = &vsp.vsp_memranges[i];
p = (void*)vmr->vmr_va;
for (j = 0; j < vmr->vmr_size; j += 2) {
if (((uint8_t*)p)[j + 0] != 0xE4)
errx(1, "bad byte");
if (((uint8_t*)p)[j + 1] != PCKBC_AUX)
errx(1, "bad byte");
}
printf("checked shared region %zu: { gpa: 0x%08lx, size: %lu,"
" hva: 0x%lx }\n", i, vmr->vmr_gpa, vmr->vmr_size,
vmr->vmr_va);
}
printf("validated shared memory mappings\n");
/*
* 3. Check that our VM exists.
*/
memset(&vip, 0, sizeof(vip));
vip.vip_size = 0;
@ -189,7 +238,7 @@ main(int argc, char **argv)
ours = NULL;
/*
* 3. Reset our VCPU and initialize register state.
* 4. Reset our VCPU and initialize register state.
*/
memset(&vresetp, 0, sizeof(vresetp));
vresetp.vrp_vm_id = vcp.vcp_id;
@ -205,7 +254,7 @@ main(int argc, char **argv)
vresetp.vrp_vm_id);
/*
* 4. Run the vcpu, expecting an immediate exit for IO assist.
* 5. Run the vcpu, expecting an immediate exit for IO assist.
*/
exit = malloc(sizeof(*exit));
if (exit == NULL) {
@ -258,7 +307,7 @@ main(int argc, char **argv)
out:
/*
* 5. Terminate our VM and clean up.
* 6. Terminate our VM and clean up.
*/
memset(&vtp, 0, sizeof(vtp));
vtp.vtp_vm_id = vcp.vcp_id;
@ -277,12 +326,22 @@ out:
vmr = &vcp.vcp_memranges[i];
if (vmr->vmr_va) {
if (munmap((void *)vmr->vmr_va, vmr->vmr_size)) {
warn("failed to unmap region %zu at 0x%08lx",
i, vmr->vmr_va);
warn("failed to unmap orginal region %zu @ hva "
"0x%lx", i, vmr->vmr_va);
ret = 1;
} else
printf("unmapped region %zu @ gpa 0x%08lx\n",
i, vmr->vmr_gpa);
printf("unmapped origin region %zu @ hva "
"0x%lx\n", i, vmr->vmr_va);
}
vmr = &vsp.vsp_memranges[i];
if (vmr->vmr_va) {
if (munmap((void *)vmr->vmr_va, vmr->vmr_size)) {
warn("failed to unmap shared region %zu @ hva "
"0x%lx", i, vmr->vmr_va);
ret = 1;
} else
printf("unmapped shared region %zu @ hva "
"0x%lx\n", i, vmr->vmr_va);
}
}

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: disklabel.8,v 1.154 2023/04/27 14:19:28 krw Exp $
.\" $OpenBSD: disklabel.8,v 1.155 2023/05/13 18:13:42 krw Exp $
.\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
@ -33,7 +33,7 @@
.\"
.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94
.\"
.Dd $Mdocdate: April 27 2023 $
.Dd $Mdocdate: May 13 2023 $
.Dt DISKLABEL 8
.Os
.Sh NAME
@ -353,7 +353,7 @@ Delete an existing partition (or
to delete all partitions).
If no partition is specified, the user will be prompted for one.
.It Cm e
Edit disk type, e.g. 'SCSI', and label description, e.g. 'UMIS RPJTJ256MED'.
Edit label description, e.g. 'UMIS RPJTJ256MED'.
.It Cm i
Change the disklabel UID, specified as a 16-character hexadecimal string.
If set to all zeros, a new UID will automatically be allocated when the

View File

@ -1,4 +1,4 @@
/* $OpenBSD: disklabel.c,v 1.248 2023/05/06 15:07:02 krw Exp $ */
/* $OpenBSD: disklabel.c,v 1.249 2023/05/13 18:13:42 krw Exp $ */
/*
* Copyright (c) 1987, 1993
@ -354,6 +354,7 @@ readlabel(int f)
lab.d_ntracks = dl.d_ntracks;
lab.d_secpercyl = dl.d_secpercyl;
lab.d_ncylinders = dl.d_ncylinders;
lab.d_type = dl.d_type;
}
}
@ -840,24 +841,6 @@ getasciilabel(FILE *f, struct disklabel *lp)
continue;
}
*tp++ = '\0', tp = skip(tp);
if (!strcmp(cp, "type")) {
if (tp == NULL)
tp = "unknown";
else if (strcasecmp(tp, "IDE") == 0)
tp = "ESDI";
cpp = dktypenames;
for (; cpp < &dktypenames[DKMAXTYPES]; cpp++)
if ((s = *cpp) && !strcasecmp(s, tp)) {
lp->d_type = cpp - dktypenames;
goto next;
}
v = GETNUM(lp->d_type, tp, 0, &errstr);
if (errstr || v >= DKMAXTYPES)
warnx("line %d: warning, unknown disk type: %s",
lineno, tp);
lp->d_type = v;
continue;
}
if (!strcmp(cp, "flags")) {
for (v = 0; (cp = tp) && *cp != '\0';) {
tp = word(cp);
@ -919,7 +902,8 @@ getasciilabel(FILE *f, struct disklabel *lp)
!strcmp(cp, "sectors/track") ||
!strcmp(cp, "sectors/cylinder") ||
!strcmp(cp, "tracks/cylinder") ||
!strcmp(cp, "cylinders"))
!strcmp(cp, "cylinders") ||
!strcmp(cp, "type"))
continue;
if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: editor.c,v 1.404 2023/04/27 14:19:28 krw Exp $ */
/* $OpenBSD: editor.c,v 1.405 2023/05/13 18:13:42 krw Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <millert@openbsd.org>
@ -136,7 +136,7 @@ struct alloc_table alloc_table_default[] = {
struct alloc_table *alloc_table = alloc_table_default;
int alloc_table_nitems = 4;
void edit_parms(struct disklabel *);
void edit_packname(struct disklabel *);
void editor_resize(struct disklabel *, const char *);
void editor_add(struct disklabel *, const char *);
void editor_change(struct disklabel *, const char *);
@ -153,7 +153,6 @@ int getpartno(const struct disklabel *, const char *, const char *);
int has_overlap(struct disklabel *);
int partition_cmp(const void *, const void *);
const struct partition **sort_partitions(const struct disklabel *, int);
void getdisktype(struct disklabel *, const char *, char *);
void find_bounds(const struct disklabel *);
void set_bounds(struct disklabel *);
void set_duid(struct disklabel *);
@ -202,10 +201,6 @@ editor(int f)
!(tmpmountpoints = calloc(MAXPARTITIONS, sizeof(char *))))
errx(4, "out of memory");
/* Don't allow disk type of "unknown" */
getdisktype(&newlab, "You need to specify a type for this disk.",
specname);
/* How big is the OpenBSD portion of the disk? */
find_bounds(&newlab);
@ -310,7 +305,7 @@ editor(int f)
break;
case 'e':
edit_parms(&newlab);
edit_packname(&newlab);
break;
case 'i':
@ -1229,41 +1224,12 @@ done:
}
void
edit_parms(struct disklabel *lp)
edit_packname(struct disklabel *lp)
{
char *p;
u_int64_t ui;
struct disklabel oldlabel = *lp;
printf("Changing disk type and label description for %s:\n", specname);
/* disk type */
for (;;) {
p = getstring("disk type",
"What kind of disk is this? Usually SCSI, ESDI, ST506, or "
"floppy (use ESDI for IDE).", dktypenames[lp->d_type]);
if (p == NULL)
return;
if (strcasecmp(p, "IDE") == 0)
ui = DTYPE_ESDI;
else
for (ui = 1; ui < DKMAXTYPES && strcasecmp(p,
dktypenames[ui]); ui++)
;
if (ui < DKMAXTYPES) {
break;
} else {
printf("\"%s\" is not a valid disk type.\n", p);
fputs("Valid types are: ", stdout);
for (ui = 1; ui < DKMAXTYPES; ui++) {
printf("\"%s\"", dktypenames[ui]);
if (ui < DKMAXTYPES - 1)
fputs(", ", stdout);
}
putchar('\n');
}
}
lp->d_type = ui;
printf("Changing label description for %s:\n", specname);
/* pack/label id */
p = getstring("label name",
@ -1302,77 +1268,6 @@ sort_partitions(const struct disklabel *lp, int ignore)
return (spp);
}
/*
* Get a valid disk type if necessary.
*/
void
getdisktype(struct disklabel *lp, const char *banner, char *dev)
{
int i;
char *s;
const char *def = "SCSI";
const struct dtypes {
const char *dev;
const char *type;
} dtypes[] = {
{ "sd", "SCSI" },
{ "wd", "IDE" },
{ "fd", "FLOPPY" },
{ "vnd", "VND" },
};
if ((s = basename(dev)) != NULL) {
if (*s == 'r')
s++;
i = strcspn(s, "0123456789");
s[i] = '\0';
dev = s;
for (i = 0; i < nitems(dtypes); i++) {
if (strcmp(dev, dtypes[i].dev) == 0) {
def = dtypes[i].type;
break;
}
}
}
if (lp->d_type > DKMAXTYPES || lp->d_type == 0) {
puts(banner);
puts("Possible values are:");
printf("\"IDE\", ");
for (i = 1; i < DKMAXTYPES; i++) {
printf("\"%s\"", dktypenames[i]);
if (i < DKMAXTYPES - 1)
fputs(", ", stdout);
}
putchar('\n');
for (;;) {
s = getstring("Disk type",
"What kind of disk is this? Usually SCSI, IDE, "
"ESDI, ST506, or floppy.", def);
if (s == NULL)
continue;
if (strcasecmp(s, "IDE") == 0) {
lp->d_type = DTYPE_ESDI;
return;
}
for (i = 1; i < DKMAXTYPES; i++)
if (strcasecmp(s, dktypenames[i]) == 0) {
lp->d_type = i;
return;
}
printf("\"%s\" is not a valid disk type.\n", s);
fputs("Valid types are: ", stdout);
for (i = 1; i < DKMAXTYPES; i++) {
printf("\"%s\"", dktypenames[i]);
if (i < DKMAXTYPES - 1)
fputs(", ", stdout);
}
putchar('\n');
}
}
}
/*
* Get beginning and ending sectors of the OpenBSD portion of the disk
* from the user.
@ -1547,7 +1442,7 @@ editor_help(void)
" c [part] - change partition size r - display free space\n"
" D - reset label to default s [path] - save label to file\n"
" d [part] - delete partition U - undo all changes\n"
" e - edit type and label name u - undo last change\n"
" e - edit label description u - undo last change\n"
" i - modify disklabel UID w - write label to disk\n"
" l [unit] - print disk label header x - exit & lose changes\n"
" M - disklabel(8) man page z - delete all partitions\n"

View File

@ -90,7 +90,7 @@ DEFINE_STATIC_SRCU(drm_unplug_srcu);
* Some functions are only called once on init regardless of how many times
* drm attaches. In linux this is handled via module_init()/module_exit()
*/
int drm_refcnt;
int drm_refcnt;
struct drm_softc {
struct device sc_dev;
@ -1225,7 +1225,7 @@ drm_attach_pci(const struct drm_driver *driver, struct pci_attach_args *pa,
sc = (struct drm_softc *)config_found_sm(dev, &arg, drmprint, drmsubmatch);
if (sc == NULL)
return NULL;
return sc->sc_drm;
}
@ -1522,7 +1522,7 @@ const struct pci_device_id *
drm_find_description(int vendor, int device, const struct pci_device_id *idlist)
{
int i = 0;
for (i = 0; idlist[i].vendor != 0; i++) {
if ((idlist[i].vendor == vendor) &&
(idlist[i].device == device ||
@ -1546,7 +1546,7 @@ struct drm_file *
drm_find_file_by_minor(struct drm_device *dev, int minor)
{
struct drm_file key;
key.fminor = minor;
return (SPLAY_FIND(drm_file_tree, &dev->files, &key));
}
@ -1886,7 +1886,7 @@ drm_dmamem_alloc(bus_dma_tag_t dmat, bus_size_t size, bus_size_t alignment,
struct drm_dmamem *mem;
size_t strsize;
/*
* segs is the last member of the struct since we modify the size
* segs is the last member of the struct since we modify the size
* to allow extra segments if more than one are allowed.
*/
strsize = sizeof(*mem) + (sizeof(bus_dma_segment_t) * (nsegments - 1));
@ -1904,7 +1904,7 @@ drm_dmamem_alloc(bus_dma_tag_t dmat, bus_size_t size, bus_size_t alignment,
&mem->nsegs, BUS_DMA_NOWAIT | BUS_DMA_ZERO) != 0)
goto destroy;
if (bus_dmamem_map(dmat, mem->segs, mem->nsegs, size,
if (bus_dmamem_map(dmat, mem->segs, mem->nsegs, size,
&mem->kva, BUS_DMA_NOWAIT | mapflags) != 0)
goto free;

View File

@ -176,10 +176,10 @@ vmmci_config_change(struct virtio_softc *vsc)
case VMMCI_SYNCRTC:
inittodr(gettime());
sc->sc_cmd = VMMCI_NONE;
break;
break;
default:
printf("%s: invalid command %d\n", sc->sc_dev.dv_xname, cmd);
cmd = VMMCI_NONE;
cmd = VMMCI_NONE;
break;
}

View File

@ -1338,7 +1338,7 @@ vmt_xdr_nic_info(char *data)
nictotal = vmt_xdr_nic_entry(iface, data);
if (nictotal == 0)
continue;
if (data != NULL)
data += nictotal;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmm.c,v 1.1 2023/04/26 15:11:21 mlarkin Exp $ */
/* $OpenBSD: vmm.c,v 1.2 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2014-2023 Mike Larkin <mlarkin@openbsd.org>
*
@ -262,6 +262,9 @@ vmmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
case VMM_IOC_WRITEVMPARAMS:
ret = vm_rwvmparams((struct vm_rwvmparams_params *)data, 1);
break;
case VMM_IOC_SHAREMEM:
ret = vm_share_mem((struct vm_sharemem_params *)data, p);
break;
default:
ret = vmmioctl_machdep(dev, cmd, data, flag, p);
break;
@ -286,6 +289,7 @@ pledge_ioctl_vmm(struct proc *p, long com)
switch (com) {
case VMM_IOC_CREATE:
case VMM_IOC_INFO:
case VMM_IOC_SHAREMEM:
/* The "parent" process in vmd forks and manages VMs */
if (p->p_p->ps_pledge & PLEDGE_PROC)
return (0);
@ -780,3 +784,82 @@ vcpu_must_stop(struct vcpu *vcpu)
return (1);
return (0);
}
/*
* vm_share_mem
*
* Share a uvm mapping for the vm guest memory ranges into the calling process.
*
* Return values:
* 0: if successful
* ENOENT: if the vm cannot be found by vm_find
* EPERM: if the vm cannot be accessed by the current process
* EINVAL: if the provide memory ranges fail checks
* ENOMEM: if uvm_share fails to find available memory in the destination map
*/
int
vm_share_mem(struct vm_sharemem_params *vsp, struct proc *p)
{
int ret = EINVAL;
size_t i, n;
struct vm *vm;
struct vm_mem_range *src, *dst;
ret = vm_find(vsp->vsp_vm_id, &vm);
if (ret)
return (ret);
/* Check we have the expected number of ranges. */
if (vm->vm_nmemranges != vsp->vsp_nmemranges)
goto out;
n = vm->vm_nmemranges;
/* Check their types, sizes, and gpa's (implying page alignment). */
for (i = 0; i < n; i++) {
src = &vm->vm_memranges[i];
dst = &vsp->vsp_memranges[i];
/*
* The vm memranges were already checked during creation, so
* compare to them to confirm validity of mapping request.
*/
if (src->vmr_type != dst->vmr_type)
goto out;
if (src->vmr_gpa != dst->vmr_gpa)
goto out;
if (src->vmr_size != dst->vmr_size)
goto out;
/* Check our intended destination is page-aligned. */
if (dst->vmr_va & PAGE_MASK)
goto out;
}
/*
* Share each range individually with the calling process. We do
* not need PROC_EXEC as the emulated devices do not need to execute
* instructions from guest memory.
*/
for (i = 0; i < n; i++) {
src = &vm->vm_memranges[i];
dst = &vsp->vsp_memranges[i];
/* Skip MMIO range. */
if (src->vmr_type == VM_MEM_MMIO)
continue;
DPRINTF("sharing gpa=0x%lx for pid %d @ va=0x%lx\n",
src->vmr_gpa, p->p_p->ps_pid, dst->vmr_va);
ret = uvm_share(&p->p_vmspace->vm_map, dst->vmr_va,
PROT_READ | PROT_WRITE, vm->vm_map, src->vmr_gpa,
src->vmr_size);
if (ret) {
printf("%s: uvm_share failed (%d)\n", __func__, ret);
break;
}
}
ret = 0;
out:
refcnt_rele_wake(&vm->vm_refcnt);
return (ret);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmm.h,v 1.2 2023/04/26 16:13:19 mlarkin Exp $ */
/* $OpenBSD: vmm.h,v 1.3 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2014-2023 Mike Larkin <mlarkin@openbsd.org>
*
@ -76,6 +76,13 @@ struct vm_resetcpu_params {
struct vcpu_reg_state vrp_init_state;
};
struct vm_sharemem_params {
/* Input parameters to VMM_IOC_SHAREMEM */
uint32_t vsp_vm_id;
size_t vsp_nmemranges;
struct vm_mem_range vsp_memranges[VMM_MAX_MEM_RANGES];
};
/* IOCTL definitions */
#define VMM_IOC_CREATE _IOWR('V', 1, struct vm_create_params) /* Create VM */
#define VMM_IOC_RUN _IOWR('V', 2, struct vm_run_params) /* Run VCPU */
@ -88,7 +95,7 @@ struct vm_resetcpu_params {
#define VMM_IOC_READVMPARAMS _IOWR('V', 9, struct vm_rwvmparams_params)
/* Set VM params */
#define VMM_IOC_WRITEVMPARAMS _IOW('V', 10, struct vm_rwvmparams_params)
#define VMM_IOC_SHAREMEM _IOW('V', 11, struct vm_sharemem_params)
#ifdef _KERNEL
@ -194,6 +201,7 @@ int vm_get_info(struct vm_info_params *);
int vm_terminate(struct vm_terminate_params *);
int vm_resetcpu(struct vm_resetcpu_params *);
int vcpu_must_stop(struct vcpu *);
int vm_share_mem(struct vm_sharemem_params *, struct proc *);
#endif /* _KERNEL */
#endif /* DEV_VMM_H */

File diff suppressed because it is too large Load Diff

View File

@ -123,8 +123,8 @@ struct x86emu_regs {
* Delayed flag set 3 bits (zero, signed, parity)
* reserved 6 bits
* interrupt # 8 bits instruction raised interrupt
* BIOS video segregs 4 bits
* Interrupt Pending 1 bits
* BIOS video segregs 4 bits
* Interrupt Pending 1 bits
* Extern interrupt 1 bits
* Halted 1 bits
*/

View File

@ -42,10 +42,10 @@
/*
* PARAMETERS:
* addr - Emulator memory address to read
*
*
* RETURNS:
* Byte value read from emulator memory.
*
*
* REMARKS:
* Reads a byte value from the emulator memory.
*/
@ -60,10 +60,10 @@ rdb(struct x86emu *emu, uint32_t addr)
/*
* PARAMETERS:
* addr - Emulator memory address to read
*
*
* RETURNS:
* Word value read from emulator memory.
*
*
* REMARKS:
* Reads a word value from the emulator memory.
*/
@ -90,7 +90,7 @@ rdw(struct x86emu *emu, uint32_t addr)
/*
* PARAMETERS:
* addr - Emulator memory address to read
*
*
* RETURNS:
* Long value read from emulator memory.
* REMARKS:
@ -122,7 +122,7 @@ rdl(struct x86emu *emu, uint32_t addr)
* PARAMETERS:
* addr - Emulator memory address to read
* val - Value to store
*
*
* REMARKS:
* Writes a byte value to emulator memory.
*/
@ -138,7 +138,7 @@ wrb(struct x86emu *emu, uint32_t addr, uint8_t val)
* PARAMETERS:
* addr - Emulator memory address to read
* val - Value to store
*
*
* REMARKS:
* Writes a word value to emulator memory.
*/
@ -164,7 +164,7 @@ wrw(struct x86emu *emu, uint32_t addr, uint16_t val)
* PARAMETERS:
* addr - Emulator memory address to read
* val - Value to store
*
*
* REMARKS:
* Writes a long value to emulator memory.
*/

View File

@ -640,7 +640,7 @@ bfd_upcall(struct socket *so, caddr_t arg, int waitflag)
struct bfd_config *bfd = (struct bfd_config *)arg;
bfd->bc_upcallso = so;
task_add(bfdtq, &bfd->bc_upcall_task);
task_add(bfdtq, &bfd->bc_upcall_task);
}
void

View File

@ -1,4 +1,4 @@
/* $OpenBSD: if.c,v 1.695 2023/05/07 16:23:23 bluhm Exp $ */
/* $OpenBSD: if.c,v 1.696 2023/05/14 01:46:53 dlg Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@ -243,8 +243,13 @@ int ifq_congestion;
int netisr;
struct softnet {
char sn_name[16];
struct taskq *sn_taskq;
};
#define NET_TASKQ 4
struct taskq *nettqmp[NET_TASKQ];
struct softnet softnets[NET_TASKQ];
struct task if_input_task_locked = TASK_INITIALIZER(if_netisr, NULL);
@ -269,8 +274,11 @@ ifinit(void)
if_idxmap_init(8); /* 8 is a nice power of 2 for malloc */
for (i = 0; i < NET_TASKQ; i++) {
nettqmp[i] = taskq_create("softnet", 1, IPL_NET, TASKQ_MPSAFE);
if (nettqmp[i] == NULL)
struct softnet *sn = &softnets[i];
snprintf(sn->sn_name, sizeof(sn->sn_name), "softnet%u", i);
sn->sn_taskq = taskq_create(sn->sn_name, 1, IPL_NET,
TASKQ_MPSAFE);
if (sn->sn_taskq == NULL)
panic("unable to create network taskq %d", i);
}
}
@ -3463,13 +3471,13 @@ unhandled_af(int af)
struct taskq *
net_tq(unsigned int ifindex)
{
struct taskq *t = NULL;
struct softnet *sn;
static int nettaskqs;
if (nettaskqs == 0)
nettaskqs = min(NET_TASKQ, ncpus);
t = nettqmp[ifindex % nettaskqs];
sn = &softnets[ifindex % nettaskqs];
return (t);
return (sn->sn_taskq);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: if_bridge.c,v 1.366 2023/05/07 16:23:23 bluhm Exp $ */
/* $OpenBSD: if_bridge.c,v 1.367 2023/05/13 13:35:17 bluhm Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@ -1735,15 +1735,8 @@ bridge_ip(struct ifnet *brifp, int dir, struct ifnet *ifp,
return (NULL);
if (m->m_len < sizeof(struct ip))
goto dropit;
in_hdr_cksum_out(m, ifp);
in_proto_cksum_out(m, ifp);
ip = mtod(m, struct ip *);
ip->ip_sum = 0;
if (0 && (ifp->if_capabilities & IFCAP_CSUM_IPv4))
m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
else {
ipstat_inc(ips_outswcsum);
ip->ip_sum = in_cksum(m, hlen);
}
#if NPF > 0
if (dir == BRIDGE_IN &&
@ -1993,8 +1986,7 @@ bridge_send_icmp_err(struct ifnet *ifp,
ip->ip_off &= htons(IP_DF);
ip->ip_id = htons(ip_randomid());
ip->ip_ttl = MAXTTL;
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, hlen);
in_hdr_cksum_out(m, NULL);
/* Swap ethernet addresses */
bcopy(&eh->ether_dhost, &ether_tmp, sizeof(ether_tmp));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: if_gre.c,v 1.173 2023/04/13 02:19:05 jsg Exp $ */
/* $OpenBSD: if_gre.c,v 1.174 2023/05/13 13:35:17 bluhm Exp $ */
/* $NetBSD: if_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */
/*
@ -3028,8 +3028,7 @@ gre_keepalive_send(void *arg)
ip = mtod(m, struct ip *);
ip->ip_id = htons(ip_randomid());
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, sizeof(*ip));
in_hdr_cksum_out(m, NULL);
proto = htons(ETHERTYPE_IP);
break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pf.c,v 1.1178 2023/05/10 12:07:16 bluhm Exp $ */
/* $OpenBSD: pf.c,v 1.1179 2023/05/13 13:35:17 bluhm Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@ -2868,7 +2868,7 @@ pf_change_icmp_af(struct mbuf *m, int ipoff2, struct pf_pdesc *pd,
ip4->ip_p = pd2->proto;
ip4->ip_src = src->v4;
ip4->ip_dst = dst->v4;
ip4->ip_sum = in_cksum(n, ip4->ip_hl << 2);
in_hdr_cksum_out(n, NULL);
break;
case AF_INET6:
ip6 = mtod(n, struct ip6_hdr *);
@ -6549,13 +6549,7 @@ pf_route(struct pf_pdesc *pd, struct pf_state *st)
}
if (ntohs(ip->ip_len) <= ifp->if_mtu) {
ip->ip_sum = 0;
if (ifp->if_capabilities & IFCAP_CSUM_IPv4)
m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
else {
ipstat_inc(ips_outswcsum);
ip->ip_sum = in_cksum(m0, ip->ip_hl << 2);
}
in_hdr_cksum_out(m0, ifp);
in_proto_cksum_out(m0, ifp);
ifp->if_output(ifp, m0, sintosa(dst), rt);
goto done;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: in.h,v 1.143 2023/05/10 12:07:16 bluhm Exp $ */
/* $OpenBSD: in.h,v 1.144 2023/05/13 13:35:17 bluhm Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
@ -779,6 +779,7 @@ int in_broadcast(struct in_addr, u_int);
int in_canforward(struct in_addr);
int in_cksum(struct mbuf *, int);
int in4_cksum(struct mbuf *, u_int8_t, int, int);
void in_hdr_cksum_out(struct mbuf *, struct ifnet *);
void in_proto_cksum_out(struct mbuf *, struct ifnet *);
int in_ifcap_cksum(struct mbuf *, struct ifnet *, int);
void in_ifdetach(struct ifnet *);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ip_divert.c,v 1.90 2023/04/04 10:12:03 bluhm Exp $ */
/* $OpenBSD: ip_divert.c,v 1.91 2023/05/13 13:35:17 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@ -157,8 +157,7 @@ divert_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam,
* since the userspace application may have modified the packet
* prior to reinjection.
*/
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, off);
in_hdr_cksum_out(m, NULL);
in_proto_cksum_out(m, NULL);
ifp = if_get(m->m_pkthdr.ph_ifidx);
@ -190,8 +189,6 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port)
struct inpcb *inp = NULL;
struct socket *so;
struct sockaddr_in sin;
struct ip *ip;
int off;
divstat_inc(divs_ipackets);
@ -239,11 +236,7 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port)
* Calculate IP and protocol checksums for outbound packet
* diverted to userland. pf rule diverts before cksum offload.
*/
ip = mtod(m, struct ip *);
off = ip->ip_hl << 2;
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, off);
in_hdr_cksum_out(m, NULL);
in_proto_cksum_out(m, NULL);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ip_output.c,v 1.385 2023/05/10 12:07:16 bluhm Exp $ */
/* $OpenBSD: ip_output.c,v 1.386 2023/05/13 13:35:17 bluhm Exp $ */
/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/*
@ -81,8 +81,7 @@ int ip_pcbopts(struct mbuf **, struct mbuf *);
int ip_multicast_if(struct ip_mreqn *, u_int, unsigned int *);
int ip_setmoptions(int, struct ip_moptions **, struct mbuf *, u_int);
void ip_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in *);
static __inline u_int16_t __attribute__((__unused__))
in_cksum_phdr(u_int32_t, u_int32_t, u_int32_t);
static u_int16_t in_cksum_phdr(u_int32_t, u_int32_t, u_int32_t);
void in_delayed_cksum(struct mbuf *);
int ip_output_ipsec_lookup(struct mbuf *m, int hlen, struct inpcb *inp,
@ -455,13 +454,7 @@ sendit:
* If small enough for interface, can just send directly.
*/
if (ntohs(ip->ip_len) <= mtu) {
ip->ip_sum = 0;
if (in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4))
m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
else {
ipstat_inc(ips_outswcsum);
ip->ip_sum = in_cksum(m, hlen);
}
in_hdr_cksum_out(m, ifp);
in_proto_cksum_out(m, ifp);
error = ifp->if_output(ifp, m, sintosa(dst), ro->ro_rt);
goto done;
@ -772,13 +765,7 @@ ip_fragment(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp,
goto bad;
}
mhip->ip_sum = 0;
if (in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4))
m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
else {
ipstat_inc(ips_outswcsum);
mhip->ip_sum = in_cksum(m, mhlen);
}
in_hdr_cksum_out(m, ifp);
}
/*
@ -791,13 +778,7 @@ ip_fragment(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp,
}
ip->ip_len = htons(m0->m_pkthdr.len);
ip->ip_sum = 0;
if (in_ifcap_cksum(m0, ifp, IFCAP_CSUM_IPv4))
m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
else {
ipstat_inc(ips_outswcsum);
ip->ip_sum = in_cksum(m0, hlen);
}
in_hdr_cksum_out(m0, ifp);
ipstat_add(ips_ofragments, ml_len(ml));
return (0);
@ -1806,7 +1787,6 @@ ip_freemoptions(struct ip_moptions *imo)
void
ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst)
{
struct ip *ip;
struct mbuf *copym;
copym = m_dup_pkt(m, max_linkhdr, M_DONTWAIT);
@ -1815,18 +1795,31 @@ ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst)
* We don't bother to fragment if the IP length is greater
* than the interface's MTU. Can this possibly matter?
*/
ip = mtod(copym, struct ip *);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(copym, ip->ip_hl << 2);
in_hdr_cksum_out(copym, NULL);
if_input_local(ifp, copym, dst->sin_family);
}
}
void
in_hdr_cksum_out(struct mbuf *m, struct ifnet *ifp)
{
struct ip *ip = mtod(m, struct ip *);
ip->ip_sum = 0;
if (ifp && in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4)) {
SET(m->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT);
} else {
ipstat_inc(ips_outswcsum);
ip->ip_sum = in_cksum(m, ip->ip_hl << 2);
CLR(m->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT);
}
}
/*
* Compute significant parts of the IPv4 checksum pseudo-header
* for use in a delayed TCP/UDP checksum calculation.
*/
static __inline u_int16_t __attribute__((__unused__))
static u_int16_t
in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
{
u_int32_t sum;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ipsec_input.c,v 1.203 2022/02/22 01:35:40 guenther Exp $ */
/* $OpenBSD: ipsec_input.c,v 1.204 2023/05/13 13:35:17 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr) and
@ -389,8 +389,7 @@ ipsec_common_input_cb(struct mbuf **mp, struct tdb *tdbp, int skip, int protoff)
ip = mtod(m, struct ip *);
ip->ip_len = htons(m->m_pkthdr.len);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, ip->ip_hl << 2);
in_hdr_cksum_out(m, NULL);
prot = ip->ip_p;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tcp_output.c,v 1.136 2023/05/10 12:07:16 bluhm Exp $ */
/* $OpenBSD: tcp_output.c,v 1.137 2023/05/13 13:35:18 bluhm Exp $ */
/* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */
/*
@ -1302,13 +1302,7 @@ tcp_chopper(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp,
*mhip = *ip;
mhip->ip_len = htons(hlen + len);
mhip->ip_id = htons(ip_randomid());
mhip->ip_sum = 0;
if (ifp && in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4)) {
m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
} else {
ipstat_inc(ips_outswcsum);
mhip->ip_sum = in_cksum(m, iphlen);
}
in_hdr_cksum_out(m, ifp);
in_proto_cksum_out(m, ifp);
}
#ifdef INET6
@ -1337,12 +1331,7 @@ tcp_chopper(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp,
if (ip) {
ip->ip_len = htons(m0->m_pkthdr.len);
ip->ip_sum = 0;
if (ifp && in_ifcap_cksum(m0, ifp, IFCAP_CSUM_IPv4)) {
m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
} else {
ipstat_inc(ips_outswcsum);
ip->ip_sum = in_cksum(m0, iphlen);
}
in_hdr_cksum_out(m0, ifp);
in_proto_cksum_out(m0, ifp);
}
#ifdef INET6

View File

@ -1,4 +1,4 @@
/* $OpenBSD: nd6.c,v 1.279 2023/05/12 12:42:16 bluhm Exp $ */
/* $OpenBSD: nd6.c,v 1.280 2023/05/13 16:27:59 bluhm Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@ -306,7 +306,7 @@ nd6_llinfo_timer(struct rtentry *rt)
struct sockaddr_in6 *dst = satosin6(rt_key(rt));
struct ifnet *ifp;
NET_ASSERT_LOCKED();
NET_ASSERT_LOCKED_EXCLUSIVE();
if ((ifp = if_get(rt->rt_ifidx)) == NULL)
return 1;
@ -557,9 +557,11 @@ nd6_lookup(const struct in6_addr *addr6, int create, struct ifnet *ifp,
rtableid);
if (error)
return (NULL);
mtx_enter(&nd6_mtx);
ln = (struct llinfo_nd6 *)rt->rt_llinfo;
if (ln != NULL)
ln->ln_state = ND6_LLINFO_NOSTATE;
mtx_leave(&nd6_mtx);
} else
return (NULL);
}
@ -665,7 +667,7 @@ nd6_free(struct rtentry *rt)
struct in6_addr in6 = satosin6(rt_key(rt))->sin6_addr;
struct ifnet *ifp;
NET_ASSERT_LOCKED();
NET_ASSERT_LOCKED_EXCLUSIVE();
ifp = if_get(rt->rt_ifidx);
@ -705,6 +707,8 @@ nd6_nud_hint(struct rtentry *rt)
struct llinfo_nd6 *ln;
struct ifnet *ifp;
NET_ASSERT_LOCKED_EXCLUSIVE();
ifp = if_get(rt->rt_ifidx);
if (ifp == NULL)
return;
@ -990,8 +994,10 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
}
rt = nd6_lookup(&nb_addr, 0, ifp, ifp->if_rdomain);
mtx_enter(&nd6_mtx);
if (rt == NULL ||
(ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) {
mtx_leave(&nd6_mtx);
rtfree(rt);
NET_UNLOCK_SHARED();
return (EINVAL);
@ -1006,6 +1012,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
nbi->asked = ln->ln_asked;
nbi->isrouter = ln->ln_router;
nbi->expire = expire;
mtx_leave(&nd6_mtx);
rtfree(rt);
NET_UNLOCK_SHARED();
@ -1035,6 +1042,8 @@ nd6_cache_lladdr(struct ifnet *ifp, const struct in6_addr *from, char *lladdr,
int llchange;
int newstate = 0;
NET_ASSERT_LOCKED_EXCLUSIVE();
if (!ifp)
panic("%s: ifp == NULL", __func__);
if (!from)
@ -1294,23 +1303,20 @@ nd6_resolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
goto bad;
}
KERNEL_LOCK();
if (!ISSET(rt->rt_flags, RTF_LLINFO)) {
KERNEL_UNLOCK();
mtx_enter(&nd6_mtx);
ln = (struct llinfo_nd6 *)rt->rt_llinfo;
if (ln == NULL) {
mtx_leave(&nd6_mtx);
goto bad;
}
ln = (struct llinfo_nd6 *)rt->rt_llinfo;
KASSERT(ln != NULL);
/*
* Move this entry to the head of the queue so that it is less likely
* for this entry to be a target of forced garbage collection (see
* nd6_rtrequest()).
*/
mtx_enter(&nd6_mtx);
TAILQ_REMOVE(&nd6_list, ln, ln_list);
TAILQ_INSERT_HEAD(&nd6_list, ln, ln_list);
mtx_leave(&nd6_mtx);
/*
* The first time we send a packet to a neighbor whose entry is
@ -1331,7 +1337,7 @@ nd6_resolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
* send the packet.
*/
if (ln->ln_state > ND6_LLINFO_INCOMPLETE) {
KERNEL_UNLOCK();
mtx_leave(&nd6_mtx);
sdl = satosdl(rt->rt_gateway);
if (sdl->sdl_alen != ETHER_ADDR_LEN) {
@ -1377,7 +1383,7 @@ nd6_resolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
saddr6 = ln->ln_saddr6;
solicit = 1;
}
KERNEL_UNLOCK();
mtx_leave(&nd6_mtx);
if (solicit)
nd6_ns_output(ifp, NULL, &satosin6(dst)->sin6_addr, &saddr6, 0);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mpls_input.c,v 1.78 2021/07/22 11:07:17 mvs Exp $ */
/* $OpenBSD: mpls_input.c,v 1.79 2023/05/13 13:35:18 bluhm Exp $ */
/*
* Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org>
@ -416,8 +416,7 @@ mpls_do_error(struct mbuf *m, int type, int code, int destmtu)
/* stuff to fix up which is normally done in ip_output */
ip->ip_v = IPVERSION;
ip->ip_id = htons(ip_randomid());
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, sizeof(*ip));
in_hdr_cksum_out(m, NULL);
/* stolen from icmp_send() */
icp = (struct icmp *)(mtod(m, caddr_t) + sizeof(*ip));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mpls_output.c,v 1.28 2019/09/03 10:39:08 jsg Exp $ */
/* $OpenBSD: mpls_output.c,v 1.29 2023/05/13 13:35:18 bluhm Exp $ */
/*
* Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org>
@ -39,7 +39,6 @@
#define MPLS_LABEL_GET(l) ((ntohl((l) & MPLS_LABEL_MASK)) >> MPLS_LABEL_OFFSET)
#endif
void mpls_do_cksum(struct mbuf *);
u_int8_t mpls_getttl(struct mbuf *, sa_family_t);
int
@ -62,7 +61,9 @@ mpls_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
}
/* need to calculate checksums now if necessary */
mpls_do_cksum(m);
if (m->m_pkthdr.csum_flags & M_IPV4_CSUM_OUT)
in_hdr_cksum_out(m, NULL);
in_proto_cksum_out(m, NULL);
/* initialize sockaddr_mpls */
bzero(&sa_mpls, sizeof(sa_mpls));
@ -143,22 +144,6 @@ bad:
return (error);
}
void
mpls_do_cksum(struct mbuf *m)
{
struct ip *ip;
u_int16_t hlen;
in_proto_cksum_out(m, NULL);
if (m->m_pkthdr.csum_flags & M_IPV4_CSUM_OUT) {
ip = mtod(m, struct ip *);
hlen = ip->ip_hl << 2;
ip->ip_sum = in_cksum(m, hlen);
m->m_pkthdr.csum_flags &= ~M_IPV4_CSUM_OUT;
}
}
u_int8_t
mpls_getttl(struct mbuf *m, sa_family_t af)
{

View File

@ -2,14 +2,14 @@
/* DragonFlyBSD:7b80531f545c7d3c51c1660130c71d01f6bccbe0:/sys/sys/blist.h */
/*
* Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
*
*
* This code is derived from software contributed to The DragonFly Project
* by Matthew Dillon <dillon@backplane.com>
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@ -19,7 +19,7 @@
* 3. Neither the name of The DragonFly Project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific, prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@ -32,7 +32,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* Implements bitmap resource lists.
*
* Usage:

View File

@ -69,16 +69,16 @@ struct cd_sub_channel_q_data {
u_int mc_valid:1;
u_int :7;
#endif
u_char mc_number[15];
u_char mc_number[15];
#if _BYTE_ORDER == _LITTLE_ENDIAN
u_int :7;
u_int ti_valid:1;
u_int ti_valid:1;
#endif
#if _BYTE_ORDER == _BIG_ENDIAN
u_int ti_valid:1;
u_int ti_valid:1;
u_int :7;
#endif
u_char ti_number[15];
u_char ti_number[15];
};
struct cd_sub_channel_position_data {
@ -272,7 +272,7 @@ struct dvd_layer {
u_int32_t end_sector;
u_int32_t end_sector_l0;
};
struct dvd_physical {
u_int8_t type;

View File

@ -51,7 +51,7 @@
/*
* Maximum length of a volume identification string
*/
*/
#define CH_VOLTAG_MAXLEN 32
/*
@ -142,7 +142,7 @@ struct changer_element_status {
struct changer_element_status_request {
int cesr_type; /* element type */
int cesr_flags;
#define CESR_VOLTAGS 0x01
#define CESR_VOLTAGS 0x01
struct changer_element_status *cesr_data; /* pre-allocated data storage */
};

View File

@ -101,7 +101,7 @@ struct clockintr_queue {
struct clockintr *cq_statclock; /* [o] statclock handle */
struct intrclock cq_intrclock; /* [I] local interrupt clock */
struct clockintr_stat cq_stat; /* [o] dispatch statistics */
volatile u_int cq_gen; /* [o] cq_stat update generation */
volatile u_int cq_gen; /* [o] cq_stat update generation */
volatile u_int cq_dispatch; /* [o] dispatch is running */
u_int cq_flags; /* [I] CQ_* flags; see below */
};

View File

@ -193,7 +193,7 @@ void new_vmcmd(struct exec_vmcmd_set *evsp,
(vmc)->evs_cnt = EXEC_DEFAULT_VMCMD_SETSIZE; \
(vmc)->evs_cmds = (vmc)->evs_start; \
(vmc)->evs_used = 0; \
} while (0)
} while (0)
/*
* Exec function switch:
@ -276,7 +276,7 @@ struct exec {
#define MID_VAX 150 /* vax */
#define MID_SPARC64 151 /* LP64 sparc */
#define MID_MIPS2 152 /* MIPS2 */
#define MID_M88K 153 /* m88k BSD binary */
#define MID_M88K 153 /* m88k BSD binary */
#define MID_HPPA 154 /* hppa */
#define MID_AMD64 157 /* AMD64 */
#define MID_MIPS64 158 /* big-endian MIPS64 */

View File

@ -270,7 +270,7 @@ typedef struct {
#define SHT_SUNW_dof 0x6ffffff4 /* used by dtrace */
#define SHT_GNU_LIBLIST 0x6ffffff7 /* libraries to be prelinked */
#define SHT_SUNW_move 0x6ffffffa /* inf for partially init'ed symbols */
#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */
#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */
#define SHT_SUNW_verdef 0x6ffffffd /* symbol versioning inf */
#define SHT_SUNW_verneed 0x6ffffffe /* symbol versioning req */
#define SHT_SUNW_versym 0x6fffffff /* symbol versioning table */

View File

@ -96,7 +96,7 @@ struct kstat_kv {
char kv_key[KSTAT_KV_NAMELEN];
union {
char v_istr[16];
unsigned int v_bool;
unsigned int v_bool;
uint64_t v_u64;
int64_t v_s64;
uint32_t v_u32;

View File

@ -60,9 +60,9 @@
#ifdef __LP64__
# define ULONG_MAX 0xffffffffffffffffUL
/* max value for unsigned long */
# define LONG_MAX 0x7fffffffffffffffL
# define LONG_MAX 0x7fffffffffffffffL
/* max value for a signed long */
# define LONG_MIN (-0x7fffffffffffffffL-1)
# define LONG_MIN (-0x7fffffffffffffffL-1)
/* min value for a signed long */
#else
# define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */
@ -71,11 +71,11 @@
#endif
#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
# define ULLONG_MAX 0xffffffffffffffffULL
# define ULLONG_MAX 0xffffffffffffffffULL
/* max value for unsigned long long */
# define LLONG_MAX 0x7fffffffffffffffLL
# define LLONG_MAX 0x7fffffffffffffffLL
/* max value for a signed long long */
# define LLONG_MIN (-0x7fffffffffffffffLL-1)
# define LLONG_MIN (-0x7fffffffffffffffLL-1)
/* min value for a signed long long */
#endif

View File

@ -1,6 +1,6 @@
/* $OpenBSD: lock.h,v 1.27 2016/06/19 11:54:33 natano Exp $ */
/*
/*
* Copyright (c) 1995
* The Regents of the University of California. All rights reserved.
*

View File

@ -398,7 +398,7 @@ struct mount {
#define MNT_DELEXPORT 0x00020000 /* delete export host lists */
#define MNT_RELOAD 0x00040000 /* reload filesystem data */
#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
#define MNT_STALLED 0x00100000 /* filesystem stalled */
#define MNT_STALLED 0x00100000 /* filesystem stalled */
#define MNT_SWAPPABLE 0x00200000 /* filesystem can be used for swap */
#define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */
#define MNT_SOFTDEP 0x04000000 /* soft dependencies being done */
@ -441,7 +441,7 @@ typedef struct fhandle fhandle_t;
#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
#define VFS_CONF 2 /* struct: vfsconf for filesystem given
as next argument */
#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given
#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given
as next argument */
#define CTL_VFSGENCTL_NAMES { \
{ 0, 0 }, \

View File

@ -72,7 +72,7 @@ struct mtget {
short mt_erreg; /* ``error'' register */
/* end device-dependent registers */
short mt_resid; /* residual count */
int mt_fileno; /* current file number relative to BOT. */
int mt_fileno; /* current file number relative to BOT. */
int mt_blkno; /* current block number relative to BOF. */
int mt_blksiz; /* current block size */
int mt_density; /* current density code */

View File

@ -356,7 +356,7 @@ struct proc {
struct plimit *p_limit; /* [l] read ref. of p_p->ps_limit */
struct kcov_dev *p_kd; /* kcov device handle */
struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */
struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */
struct kqueue *p_kq; /* [o] select/poll queue of evts */
unsigned long p_kq_serial; /* [o] to check against enqueued evts */

View File

@ -106,7 +106,7 @@ struct protosw {
/* user-protocol hooks */
const struct pr_usrreqs *pr_usrreqs;
/* utility hooks */
void (*pr_init)(void); /* initialization hook */
void (*pr_fasttimo)(void); /* fast timeout (200ms) */

View File

@ -106,7 +106,7 @@ struct schedstate_percpu {
u_char spc_curpriority; /* usrpri of curproc */
int spc_rrticks; /* ticks until roundrobin() */
int spc_pscnt; /* prof/stat counter */
int spc_psdiv; /* prof/stat divisor */
int spc_psdiv; /* prof/stat divisor */
u_int spc_nrun; /* procs on the run queues */
fixpt_t spc_ldavg; /* shortest load avg. for this cpu */

View File

@ -60,7 +60,7 @@ struct scsi_addr {
};
#define SCIOCRESET _IO('Q', 7) /* reset the device */
#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr)
#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr)
struct sbioc_device {
void *sd_cookie;

View File

@ -29,19 +29,19 @@
#define _SYS_SIGINFO_H
#include <sys/cdefs.h>
union sigval {
int sival_int; /* integer value */
void *sival_ptr; /* pointer value */
};
/*
* Negative signal codes are reserved for future use for
* user generated signals.
*/
#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
#define SI_FROMKERNEL(sip) ((sip)->si_code > 0)
#define SI_NOINFO 32767 /* no signal information */
#define SI_USER 0 /* user generated signal via kill() */
#define SI_LWP (-1) /* user generated signal via lwp_kill()*/

View File

@ -174,7 +174,7 @@
#define SIOCDVNETID _IOW('i', 175, struct ifreq) /* del virt net id */
#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */
#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */
#define SIOCGIFPAIR _IOWR('i', 177, struct ifreq) /* get paired if */
#define SIOCSIFPARENT _IOW('i', 178, struct if_parent) /* set parent if */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_aobj.c,v 1.107 2022/08/29 02:58:13 jsg Exp $ */
/* $OpenBSD: uvm_aobj.c,v 1.108 2023/05/13 09:24:59 mpi Exp $ */
/* $NetBSD: uvm_aobj.c,v 1.39 2001/02/18 21:19:08 chs Exp $ */
/*
@ -143,7 +143,6 @@ struct pool uvm_aobj_pool;
static struct uao_swhash_elt *uao_find_swhash_elt(struct uvm_aobj *, int,
boolean_t);
static int uao_find_swslot(struct uvm_object *, int);
static boolean_t uao_flush(struct uvm_object *, voff_t,
voff_t, int);
static void uao_free(struct uvm_aobj *);
@ -241,7 +240,7 @@ uao_find_swhash_elt(struct uvm_aobj *aobj, int pageidx, boolean_t create)
/*
* uao_find_swslot: find the swap slot number for an aobj/pageidx
*/
static inline int
int
uao_find_swslot(struct uvm_object *uobj, int pageidx)
{
struct uvm_aobj *aobj = (struct uvm_aobj *)uobj;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_aobj.h,v 1.19 2022/07/24 11:00:22 mpi Exp $ */
/* $OpenBSD: uvm_aobj.h,v 1.20 2023/05/13 09:24:59 mpi Exp $ */
/* $NetBSD: uvm_aobj.h,v 1.10 2000/01/11 06:57:49 chs Exp $ */
/*
@ -60,6 +60,7 @@
void uao_init(void);
int uao_set_swslot(struct uvm_object *, int, int);
int uao_find_swslot(struct uvm_object *, int);
int uao_dropswap(struct uvm_object *, int);
int uao_swap_off(int, int);
int uao_shrink(struct uvm_object *, int);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_page.c,v 1.171 2023/04/11 00:45:09 jsg Exp $ */
/* $OpenBSD: uvm_page.c,v 1.172 2023/05/13 09:24:59 mpi Exp $ */
/* $NetBSD: uvm_page.c,v 1.44 2000/11/27 08:40:04 chs Exp $ */
/*
@ -1036,13 +1036,14 @@ uvm_pagefree(struct vm_page *pg)
* uvm_page_unbusy: unbusy an array of pages.
*
* => pages must either all belong to the same object, or all belong to anons.
* => if pages are object-owned, object must be locked.
* => if pages are anon-owned, anons must have 0 refcount.
* => caller must make sure that anon-owned pages are not PG_RELEASED.
*/
void
uvm_page_unbusy(struct vm_page **pgs, int npgs)
{
struct vm_page *pg;
struct uvm_object *uobj;
int i;
for (i = 0; i < npgs; i++) {
@ -1052,35 +1053,20 @@ uvm_page_unbusy(struct vm_page **pgs, int npgs)
continue;
}
#if notyet
/*
* XXX swap case in uvm_aio_aiodone() is not holding the lock.
*
* This isn't compatible with the PG_RELEASED anon case below.
*/
KASSERT(uvm_page_owner_locked_p(pg));
#endif
KASSERT(pg->pg_flags & PG_BUSY);
if (pg->pg_flags & PG_WANTED) {
wakeup(pg);
}
if (pg->pg_flags & PG_RELEASED) {
uobj = pg->uobject;
if (uobj != NULL) {
uvm_lock_pageq();
pmap_page_protect(pg, PROT_NONE);
/* XXX won't happen right now */
if (pg->pg_flags & PQ_AOBJ)
uao_dropswap(uobj,
pg->offset >> PAGE_SHIFT);
uvm_pagefree(pg);
uvm_unlock_pageq();
} else {
rw_enter(pg->uanon->an_lock, RW_WRITE);
uvm_anon_release(pg->uanon);
}
KASSERT(pg->uobject != NULL ||
(pg->uanon != NULL && pg->uanon->an_ref > 0));
atomic_clearbits_int(&pg->pg_flags, PG_RELEASED);
pmap_page_protect(pg, PROT_NONE);
uvm_pagefree(pg);
} else {
KASSERT((pg->pg_flags & PG_FAKE) == 0);
atomic_clearbits_int(&pg->pg_flags, PG_WANTED|PG_BUSY);
UVM_PAGE_OWN(pg, NULL);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uvm_pager.c,v 1.89 2022/08/19 05:53:19 mpi Exp $ */
/* $OpenBSD: uvm_pager.c,v 1.90 2023/05/13 09:24:59 mpi Exp $ */
/* $NetBSD: uvm_pager.c,v 1.36 2000/11/27 18:26:41 chs Exp $ */
/*
@ -755,50 +755,77 @@ void
uvm_aio_aiodone_pages(struct vm_page **pgs, int npages, boolean_t write,
int error)
{
struct vm_page *pg;
struct uvm_object *uobj;
struct vm_page *pg;
struct rwlock *slock;
boolean_t swap;
int i;
int i, swslot;
slock = NULL;
uobj = NULL;
pg = pgs[0];
swap = (pg->uanon != NULL && pg->uobject == NULL) ||
(pg->pg_flags & PQ_AOBJ) != 0;
KASSERT(swap);
KASSERT(write);
if (error) {
if (pg->uobject != NULL) {
swslot = uao_find_swslot(pg->uobject,
pg->offset >> PAGE_SHIFT);
} else {
swslot = pg->uanon->an_swslot;
}
KASSERT(swslot);
}
for (i = 0; i < npages; i++) {
int anon_disposed = 0;
pg = pgs[i];
if (i == 0) {
swap = (pg->pg_flags & PQ_SWAPBACKED) != 0;
if (!swap) {
uobj = pg->uobject;
rw_enter(uobj->vmobjlock, RW_WRITE);
}
}
KASSERT(swap || pg->uobject == uobj);
KASSERT((pg->pg_flags & PG_FAKE) == 0);
/*
* if this is a read and we got an error, mark the pages
* PG_RELEASED so that uvm_page_unbusy() will free them.
* lock each page's object (or anon) individually since
* each page may need a different lock.
*/
if (!write && error) {
atomic_setbits_int(&pg->pg_flags, PG_RELEASED);
continue;
if (pg->uobject != NULL) {
slock = pg->uobject->vmobjlock;
} else {
slock = pg->uanon->an_lock;
}
KASSERT(!write || (pgs[i]->pg_flags & PG_FAKE) == 0);
rw_enter(slock, RW_WRITE);
anon_disposed = (pg->pg_flags & PG_RELEASED) != 0;
KASSERT(!anon_disposed || pg->uobject != NULL ||
pg->uanon->an_ref == 0);
uvm_lock_pageq();
/*
* if this is a read and the page is PG_FAKE,
* or this was a successful write,
* mark the page PG_CLEAN and not PG_FAKE.
* if this was a successful write,
* mark the page PG_CLEAN.
*/
if ((pgs[i]->pg_flags & PG_FAKE) || (write && error != ENOMEM)) {
pmap_clear_reference(pgs[i]);
pmap_clear_modify(pgs[i]);
atomic_setbits_int(&pgs[i]->pg_flags, PG_CLEAN);
atomic_clearbits_int(&pgs[i]->pg_flags, PG_FAKE);
if (!error) {
pmap_clear_reference(pg);
pmap_clear_modify(pg);
atomic_setbits_int(&pg->pg_flags, PG_CLEAN);
}
/*
* unlock everything for this page now.
*/
if (pg->uobject == NULL && anon_disposed) {
uvm_unlock_pageq();
uvm_anon_release(pg->uanon);
} else {
uvm_page_unbusy(&pg, 1);
uvm_unlock_pageq();
rw_exit(slock);
}
}
uvm_page_unbusy(pgs, npages);
if (!swap) {
rw_exit(uobj->vmobjlock);
if (error) {
uvm_swap_markbad(swslot, npages);
}
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vioblk.c,v 1.2 2023/04/28 18:52:22 dv Exp $ */
/* $OpenBSD: vioblk.c,v 1.3 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2023 Dave Voutila <dv@openbsd.org>
@ -58,7 +58,7 @@ disk_type(int type)
}
__dead void
vioblk_main(int fd)
vioblk_main(int fd, int fd_vmm)
{
struct virtio_dev dev;
struct vioblk_dev *vioblk;
@ -71,8 +71,11 @@ vioblk_main(int fd)
log_procinit("vioblk");
/* stdio - needed for read/write to disk fds and channels to the vm. */
if (pledge("stdio", NULL) == -1)
/*
* stdio - needed for read/write to disk fds and channels to the vm.
* vmm + proc - needed to create shared vm mappings.
*/
if (pledge("stdio vmm proc", NULL) == -1)
fatal("pledge");
/* Receive our virtio_dev, mostly preconfigured. */
@ -92,8 +95,9 @@ vioblk_main(int fd)
vioblk = &dev.vioblk;
log_debug("%s: got viblk dev. num disk fds = %d, sync fd = %d, "
"async fd = %d, sz = %lld maxfer = %d", __func__, vioblk->ndisk_fd,
dev.sync_fd, dev.async_fd, vioblk->sz, vioblk->max_xfer);
"async fd = %d, sz = %lld maxfer = %d, vmm fd = %d", __func__,
vioblk->ndisk_fd, dev.sync_fd, dev.async_fd, vioblk->sz,
vioblk->max_xfer, fd_vmm);
/* Receive our vm information from the vm process. */
memset(&vm, 0, sizeof(vm));
@ -108,12 +112,19 @@ vioblk_main(int fd)
setproctitle("%s/vioblk[%d]", vcp->vcp_name, vioblk->idx);
/* Now that we have our vm information, we can remap memory. */
ret = remap_guest_mem(&vm);
ret = remap_guest_mem(&vm, fd_vmm);
if (ret) {
log_warnx("failed to remap guest memory");
goto fail;
}
/*
* We no longer need /dev/vmm access.
*/
close_fd(fd_vmm);
if (pledge("stdio", NULL) == -1)
fatal("pledge2");
/* Initialize the virtio block abstractions. */
type = vm.vm_params.vmc_disktypes[vioblk->idx];
switch (type) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vionet.c,v 1.2 2023/04/28 18:52:22 dv Exp $ */
/* $OpenBSD: vionet.c,v 1.3 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2023 Dave Voutila <dv@openbsd.org>
@ -61,7 +61,7 @@ static void dev_dispatch_vm(int, short, void *);
static void handle_sync_io(int, short, void *);
__dead void
vionet_main(int fd)
vionet_main(int fd, int fd_vmm)
{
struct virtio_dev dev;
struct vionet_dev *vionet = NULL;
@ -73,8 +73,11 @@ vionet_main(int fd)
log_procinit("vionet");
/* stdio - needed for read/write to tap fd and channels to the vm. */
if (pledge("stdio", NULL) == -1)
/*
* stdio - needed for read/write to disk fds and channels to the vm.
* vmm + proc - needed to create shared vm mappings.
*/
if (pledge("stdio vmm proc", NULL) == -1)
fatal("pledge");
/* Receive our vionet_dev, mostly preconfigured. */
@ -92,8 +95,9 @@ vionet_main(int fd)
dev.sync_fd = fd;
vionet = &dev.vionet;
log_debug("%s: got vionet dev. tap fd = %d, syncfd = %d, asyncfd = %d",
__func__, vionet->data_fd, dev.sync_fd, dev.async_fd);
log_debug("%s: got vionet dev. tap fd = %d, syncfd = %d, asyncfd = %d"
", vmm fd = %d", __func__, vionet->data_fd, dev.sync_fd,
dev.async_fd, fd_vmm);
/* Receive our vm information from the vm process. */
memset(&vm, 0, sizeof(vm));
@ -108,9 +112,18 @@ vionet_main(int fd)
setproctitle("%s/vionet[%d]", vcp->vcp_name, vionet->idx);
/* Now that we have our vm information, we can remap memory. */
ret = remap_guest_mem(&vm);
if (ret)
ret = remap_guest_mem(&vm, fd_vmm);
if (ret) {
fatal("%s: failed to remap", __func__);
goto fail;
}
/*
* We no longer need /dev/vmm access.
*/
close_fd(fd_vmm);
if (pledge("stdio", NULL) == -1)
fatal("pledge2");
/* If we're restoring hardware, re-initialize virtqueue hva's. */
if (vm.vm_state & VM_STATE_RECEIVED) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: virtio.c,v 1.102 2023/04/27 22:47:27 dv Exp $ */
/* $OpenBSD: virtio.c,v 1.103 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@ -1297,7 +1297,7 @@ virtio_start(struct vmd_vm *vm)
static int
virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev)
{
char *nargv[8], num[32], t[2];
char *nargv[10], num[32], vmm_fd[32], t[2];
pid_t dev_pid;
int data_fds[VM_MAX_BASE_PER_DISK], sync_fds[2], async_fds[2], ret = 0;
size_t i, j, data_fds_sz, sz = 0;
@ -1483,6 +1483,8 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev)
memset(&nargv, 0, sizeof(nargv));
memset(num, 0, sizeof(num));
snprintf(num, sizeof(num), "%d", sync_fds[1]);
memset(vmm_fd, 0, sizeof(vmm_fd));
snprintf(vmm_fd, sizeof(vmm_fd), "%d", env->vmd_fd);
t[0] = dev->dev_type;
t[1] = '\0';
@ -1492,13 +1494,15 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev)
nargv[2] = num;
nargv[3] = "-t";
nargv[4] = t;
nargv[5] = "-n";
nargv[5] = "-i";
nargv[6] = vmm_fd;
nargv[7] = "-n";
if (env->vmd_verbose) {
nargv[6] = "-v";
nargv[7] = NULL;
nargv[8] = "-v";
nargv[9] = NULL;
} else
nargv[6] = NULL;
nargv[8] = NULL;
/* Control resumes in vmd.c:main(). */
execvp(nargv[0], nargv);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vm.c,v 1.88 2023/04/28 19:46:42 dv Exp $ */
/* $OpenBSD: vm.c,v 1.89 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@ -218,9 +218,10 @@ static const struct vcpu_reg_state vcpu_init_flat16 = {
* Primary entrypoint for launching a vm. Does not return.
*
* fd: file descriptor for communicating with vmm process.
* fd_vmm: file descriptor for communicating with vmm(4) device
*/
void
vm_main(int fd)
vm_main(int fd, int vmm_fd)
{
struct vm_create_params *vcp = NULL;
struct vmd_vm vm;
@ -241,9 +242,8 @@ vm_main(int fd)
* vmm - for the vmm ioctls and operations.
* proc exec - fork/exec for launching devices.
* recvfd - for vm send/recv and sending fd to devices.
* tmppath/rpath - for shm_mkstemp, ftruncate, unlink
*/
if (pledge("stdio vmm proc exec recvfd tmppath rpath", NULL) == -1)
if (pledge("stdio vmm proc exec recvfd", NULL) == -1)
fatal("pledge");
/* Receive our vm configuration. */
@ -254,13 +254,6 @@ vm_main(int fd)
_exit(EIO);
}
/* Receive the /dev/vmm fd number. */
sz = atomicio(read, fd, &env->vmd_fd, sizeof(env->vmd_fd));
if (sz != sizeof(env->vmd_fd)) {
log_warnx("failed to receive /dev/vmm fd");
_exit(EIO);
}
/* Update process with the vm name. */
vcp = &vm.vm_params.vmc_params;
setproctitle("%s", vcp->vcp_name);
@ -1099,63 +1092,34 @@ int
alloc_guest_mem(struct vmd_vm *vm)
{
void *p;
char *tmp;
int fd, ret = 0;
int ret = 0;
size_t i, j;
struct vm_create_params *vcp = &vm->vm_params.vmc_params;
struct vm_mem_range *vmr;
tmp = calloc(32, sizeof(char));
if (tmp == NULL) {
ret = errno;
log_warn("%s: calloc", __func__);
return (ret);
}
strlcpy(tmp, "/tmp/vmd.XXXXXXXXXX", 32);
vm->vm_nmemfds = vcp->vcp_nmemranges;
for (i = 0; i < vcp->vcp_nmemranges; i++) {
vmr = &vcp->vcp_memranges[i];
fd = shm_mkstemp(tmp);
if (fd < 0) {
ret = errno;
log_warn("%s: shm_mkstemp", __func__);
return (ret);
}
if (ftruncate(fd, vmr->vmr_size) == -1) {
ret = errno;
log_warn("%s: ftruncate", __func__);
goto out;
}
if (fcntl(fd, F_SETFD, 0) == -1) {
ret = errno;
log_warn("%s: fcntl", __func__);
goto out;
}
if (shm_unlink(tmp) == -1) {
ret = errno;
log_warn("%s: shm_unlink", __func__);
goto out;
}
strlcpy(tmp, "/tmp/vmd.XXXXXXXXXX", 32);
/*
* We only need R/W as userland. vmm(4) will use R/W/X in its
* mapping.
*
* We must use MAP_SHARED so emulated devices will be able
* to generate shared mappings.
*/
p = mmap(NULL, vmr->vmr_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_CONCEAL, fd, 0);
MAP_ANON | MAP_CONCEAL | MAP_SHARED, -1, 0);
if (p == MAP_FAILED) {
ret = errno;
for (j = 0; j < i; j++) {
vmr = &vcp->vcp_memranges[j];
munmap((void *)vmr->vmr_va, vmr->vmr_size);
}
goto out;
return (ret);
}
vm->vm_memfds[i] = fd;
vmr->vmr_va = (vaddr_t)p;
}
out:
free(tmp);
return (ret);
}
@ -2552,10 +2516,11 @@ vm_pipe_recv(struct vm_dev_pipe *p)
* Returns 0 on success, non-zero in event of failure.
*/
int
remap_guest_mem(struct vmd_vm *vm)
remap_guest_mem(struct vmd_vm *vm, int vmm_fd)
{
struct vm_create_params *vcp;
struct vm_mem_range *vmr;
struct vm_sharemem_params vsp;
size_t i, j;
void *p = NULL;
int ret;
@ -2566,23 +2531,32 @@ remap_guest_mem(struct vmd_vm *vm)
vcp = &vm->vm_params.vmc_params;
/*
* We've execve'd, so we need to re-map the guest VM memory. Iterate
* over all possible vm_mem_range entries so we can initialize all
* file descriptors to a value.
* Initialize our VM shared memory request using our original
* creation parameters. We'll overwrite the va's after mmap(2).
*/
memset(&vsp, 0, sizeof(vsp));
vsp.vsp_nmemranges = vcp->vcp_nmemranges;
vsp.vsp_vm_id = vcp->vcp_id;
memcpy(&vsp.vsp_memranges, &vcp->vcp_memranges,
sizeof(vsp.vsp_memranges));
/*
* Use mmap(2) to identify virtual address space for our mappings.
*/
for (i = 0; i < VMM_MAX_MEM_RANGES; i++) {
if (i < vcp->vcp_nmemranges) {
vmr = &vcp->vcp_memranges[i];
/* Skip ranges we know we don't need right now. */
if (i < vsp.vsp_nmemranges) {
vmr = &vsp.vsp_memranges[i];
/* Ignore any MMIO ranges. */
if (vmr->vmr_type == VM_MEM_MMIO) {
log_debug("%s: skipping range i=%ld, type=%d",
__func__, i, vmr->vmr_type);
vm->vm_memfds[i] = -1;
vmr->vmr_va = 0;
vcp->vcp_memranges[i].vmr_va = 0;
continue;
}
/* Re-mmap the memrange. */
p = mmap(NULL, vmr->vmr_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_CONCEAL, vm->vm_memfds[i], 0);
/* Make initial mappings for the memrange. */
p = mmap(NULL, vmr->vmr_size, PROT_READ, MAP_ANON, -1,
0);
if (p == MAP_FAILED) {
ret = errno;
log_warn("%s: mmap", __func__);
@ -2594,11 +2568,29 @@ remap_guest_mem(struct vmd_vm *vm)
return (ret);
}
vmr->vmr_va = (vaddr_t)p;
} else {
/* Initialize with an invalid fd. */
vm->vm_memfds[i] = -1;
vcp->vcp_memranges[i].vmr_va = vmr->vmr_va;
}
}
/*
* munmap(2) now that we have va's and ranges that don't overlap. vmm
* will use the va's and sizes to recreate the mappings for us.
*/
for (i = 0; i < vsp.vsp_nmemranges; i++) {
vmr = &vsp.vsp_memranges[i];
if (vmr->vmr_type == VM_MEM_MMIO)
continue;
if (munmap((void*)vmr->vmr_va, vmr->vmr_size) == -1)
fatal("%s: munmap", __func__);
}
/*
* Ask vmm to enter the shared mappings for us. They'll point
* to the same host physical memory, but will have a randomized
* virtual address for the calling process.
*/
if (ioctl(vmm_fd, VMM_IOC_SHAREMEM, &vsp) == -1)
return (errno);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmd.c,v 1.148 2023/05/12 16:18:17 dv Exp $ */
/* $OpenBSD: vmd.c,v 1.149 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@ -788,7 +788,8 @@ main(int argc, char **argv)
struct privsep *ps;
int ch;
enum privsep_procid proc_id = PROC_PARENT;
int proc_instance = 0, vm_launch = 0, vm_fd = -1;
int proc_instance = 0, vm_launch = 0;
int vmm_fd = -1, vm_fd = -1;
const char *errp, *title = NULL;
int argc0 = argc;
char dev_type = '\0';
@ -798,7 +799,7 @@ main(int argc, char **argv)
if ((env = calloc(1, sizeof(*env))) == NULL)
fatal("calloc: env");
while ((ch = getopt(argc, argv, "D:P:I:V:X:df:nt:v")) != -1) {
while ((ch = getopt(argc, argv, "D:P:I:V:X:df:i:nt:v")) != -1) {
switch (ch) {
case 'D':
if (cmdline_symset(optarg) < 0)
@ -852,6 +853,11 @@ main(int argc, char **argv)
default: fatalx("invalid device type");
}
break;
case 'i':
vmm_fd = strtonum(optarg, 0, 128, &errp);
if (errp)
fatalx("invalid vmm fd");
break;
default:
usage();
}
@ -880,7 +886,7 @@ main(int argc, char **argv)
ps = &env->vmd_ps;
ps->ps_env = env;
env->vmd_fd = -1;
env->vmd_fd = vmm_fd;
if (config_init(env) == -1)
fatal("failed to initialize configuration");
@ -896,14 +902,14 @@ main(int argc, char **argv)
* If we're launching a new vm or its device, we short out here.
*/
if (vm_launch == VMD_LAUNCH_VM) {
vm_main(vm_fd);
vm_main(vm_fd, vmm_fd);
/* NOTREACHED */
} else if (vm_launch == VMD_LAUNCH_DEV) {
if (dev_type == VMD_DEVTYPE_NET) {
vionet_main(vm_fd);
vionet_main(vm_fd, vmm_fd);
/* NOTREACHED */
} else if (dev_type == VMD_DEVTYPE_DISK) {
vioblk_main(vm_fd);
vioblk_main(vm_fd, vmm_fd);
/* NOTREACHED */
}
fatalx("unsupported device type '%c'", dev_type);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmd.h,v 1.121 2023/04/28 19:46:42 dv Exp $ */
/* $OpenBSD: vmd.h,v 1.122 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@ -329,9 +329,6 @@ struct vmd_vm {
struct timeval vm_start_tv;
int vm_start_limit;
int vm_memfds[VMM_MAX_MEM_RANGES];
size_t vm_nmemfds;
TAILQ_ENTRY(vmd_vm) vm_entry;
};
TAILQ_HEAD(vmlist, vmd_vm);
@ -488,7 +485,7 @@ int fd_hasdata(int);
int vmm_pipe(struct vmd_vm *, int, void (*)(int, short, void *));
/* vm.c */
void vm_main(int);
void vm_main(int, int);
void mutex_lock(pthread_mutex_t *);
void mutex_unlock(pthread_mutex_t *);
int read_mem(paddr_t, void *buf, size_t);
@ -499,7 +496,7 @@ void vm_pipe_send(struct vm_dev_pipe *, enum pipe_msg_type);
enum pipe_msg_type vm_pipe_recv(struct vm_dev_pipe *);
int write_mem(paddr_t, const void *buf, size_t);
void* hvaddr_mem(paddr_t, size_t);
int remap_guest_mem(struct vmd_vm *);
int remap_guest_mem(struct vmd_vm *, int);
/* config.c */
int config_init(struct vmd *);
@ -527,9 +524,9 @@ int host(const char *, struct address *);
int virtio_get_base(int, char *, size_t, int, const char *);
/* vionet.c */
__dead void vionet_main(int);
__dead void vionet_main(int, int);
/* vioblk.c */
__dead void vioblk_main(int);
__dead void vioblk_main(int, int);
#endif /* VMD_H */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmm.c,v 1.111 2023/04/27 22:47:27 dv Exp $ */
/* $OpenBSD: vmm.c,v 1.112 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@ -627,7 +627,7 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid)
{
struct vm_create_params *vcp;
struct vmd_vm *vm;
char *nargv[6], num[32];
char *nargv[8], num[32], vmm_fd[32];
int fd, ret = EINVAL;
int fds[2];
pid_t vm_pid;
@ -701,16 +701,6 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid)
if (ret == EIO)
goto err;
/* Send the fd number for /dev/vmm. */
sz = atomicio(vwrite, fds[0], &env->vmd_fd,
sizeof(env->vmd_fd));
if (sz != sizeof(env->vmd_fd)) {
log_warnx("%s: failed to send /dev/vmm fd for vm '%s'",
__func__, vcp->vcp_name);
ret = EIO;
goto err;
}
/* Read back the kernel-generated vm id from the child */
sz = atomicio(read, fds[0], &vcp->vcp_id, sizeof(vcp->vcp_id));
if (sz != sizeof(vcp->vcp_id)) {
@ -773,17 +763,21 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid)
memset(&nargv, 0, sizeof(nargv));
memset(num, 0, sizeof(num));
snprintf(num, sizeof(num), "%d", fds[1]);
memset(vmm_fd, 0, sizeof(vmm_fd));
snprintf(vmm_fd, sizeof(vmm_fd), "%d", env->vmd_fd);
nargv[0] = env->argv0;
nargv[1] = "-V";
nargv[2] = num;
nargv[3] = "-n";
nargv[4] = "-i";
nargv[5] = vmm_fd;
if (env->vmd_verbose) {
nargv[4] = "-v";
nargv[5] = NULL;
nargv[6] = "-v";
nargv[7] = NULL;
} else
nargv[4] = NULL;
nargv[6] = NULL;
/* Control resumes in vmd main(). */
execvp(nargv[0], nargv);