git: c7581d76a1e4 - main - loader: fix stupid typos

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=c7581d76a1e46a925bba59d3e18394908f65c907

commit c7581d76a1e46a925bba59d3e18394908f65c907
Author: Warner Losh 
AuthorDate: 2024-05-20 05:04:18 +
Commit: Warner Losh 
CommitDate: 2024-05-20 05:04:18 +

loader: fix stupid typos

Sponsored by:   Netflix
---
 stand/libofw/ofw_console.c  | 2 +-
 stand/uboot/uboot_console.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/stand/libofw/ofw_console.c b/stand/libofw/ofw_console.c
index 75f9bfba0968..6925641eb606 100644
--- a/stand/libofw/ofw_console.c
+++ b/stand/libofw/ofw_console.c
@@ -41,7 +41,7 @@ static ihandle_t stdin;
 static ihandle_t stdout;
 
 struct console ofwconsole = {
-   .c_cname = "ofw",
+   .c_name = "ofw",
.c_desc = "Open Firmware console",
.c_probe = ofw_cons_probe,
.c_init = ofw_cons_init,
diff --git a/stand/uboot/uboot_console.c b/stand/uboot/uboot_console.c
index c02ba9aba5f0..b850a88c4018 100644
--- a/stand/uboot/uboot_console.c
+++ b/stand/uboot/uboot_console.c
@@ -42,7 +42,7 @@ struct console uboot_console = {
.c_probe = uboot_cons_probe,
.c_init = uboot_cons_init,
.c_out = uboot_cons_putchar,
-   .c_int = uboot_cons_getchar,
+   .c_in = uboot_cons_getchar,
.c_ready = uboot_cons_poll,
 };
 



git: 861f802b3eba - main - textvidc: Reindent

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=861f802b3ebaf05075c6dd8be25f802c3e6527b6

commit 861f802b3ebaf05075c6dd8be25f802c3e6527b6
Author: Warner Losh 
AuthorDate: 2024-05-19 21:18:58 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:43 +

textvidc: Reindent

Since this is now 'new code' go ahead and reindent for modern project
preferences.

Sponsored by:   Netflix
---
 stand/i386/libi386/textvidc.c | 683 +-
 1 file changed, 343 insertions(+), 340 deletions(-)

diff --git a/stand/i386/libi386/textvidc.c b/stand/i386/libi386/textvidc.c
index 75d498930119..1dd950bc4021 100644
--- a/stand/i386/libi386/textvidc.c
+++ b/stand/i386/libi386/textvidc.c
@@ -82,112 +82,112 @@ struct console textvidc = {
 static void
 vidc_probe(struct console *cp)
 {
-/* look for a keyboard */
+   /* look for a keyboard */
 #if KEYBOARD_PROBE
-if (probe_keyboard())
+   if (probe_keyboard())
 #endif
-{
-   cp->c_flags |= C_PRESENTIN;
-}
+   {
+   cp->c_flags |= C_PRESENTIN;
+   }
 
-/* XXX for now, always assume we can do BIOS screen output */
-cp->c_flags |= C_PRESENTOUT;
+   /* XXX for now, always assume we can do BIOS screen output */
+   cp->c_flags |= C_PRESENTOUT;
 }
 
 static int
 vidc_init(int arg)
 {
-inti;
+   int i;
 
-if (vidc_started && arg == 0)
-   return (0);
-vidc_started = 1;
+   if (vidc_started && arg == 0)
+   return (0);
+   vidc_started = 1;
 #ifdef TERM_EMU
-/* Init terminal emulator */
-end_term();
-get_pos(, );
-curs_move(, , curx, cury);
-fg_c = DEFAULT_FGCOLOR;
-bg_c = DEFAULT_BGCOLOR;
+   /* Init terminal emulator */
+   end_term();
+   get_pos(, );
+   curs_move(, , curx, cury);
+   fg_c = DEFAULT_FGCOLOR;
+   bg_c = DEFAULT_BGCOLOR;
 #endif
-for (i = 0; i < 10 && vidc_ischar(); i++)
-   (void)vidc_getchar();
-return (0);/* XXX reinit? */
+   for (i = 0; i < 10 && vidc_ischar(); i++)
+   (void)vidc_getchar();
+   return (0); /* XXX reinit? */
 }
 
 static void
 vidc_biosputchar(int c)
 {
 
-v86.ctl = 0;
-v86.addr = 0x10;
-v86.eax = 0xe00 | (c & 0xff);
-v86.ebx = 0x7;
-v86int();
+   v86.ctl = 0;
+   v86.addr = 0x10;
+   v86.eax = 0xe00 | (c & 0xff);
+   v86.ebx = 0x7;
+   v86int();
 }
 
 static void
 vidc_rawputchar(int c)
 {
-inti;
+   int i;
 
-if (c == '\t') {
-   int n;
+   if (c == '\t') {
+   int n;
 #ifndef TERM_EMU
-   int curx, cury;
+   int curx, cury;
 
-   get_pos(, );
+   get_pos(, );
 #endif
 
-   n = 8 - ((curx + 8) % 8);
-   for (i = 0; i < n; i++)
-   vidc_rawputchar(' ');
-} else {
+   n = 8 - ((curx + 8) % 8);
+   for (i = 0; i < n; i++)
+   vidc_rawputchar(' ');
+   } else {
 #ifndef TERM_EMU
-vidc_biosputchar(c);
+   vidc_biosputchar(c);
 #else
-   /* Emulate AH=0eh (teletype output) */
-   switch(c) {
-   case '\a':
-   vidc_biosputchar(c);
-   return;
-   case '\r':
-   curx = 0;
-   curs_move(, , curx, cury);
-   return;
-   case '\n':
-   cury++;
-   if (cury > 24) {
-   scroll_up(1, fg_c, bg_c);
-   cury--;
-   } else {
-   curs_move(, , curx, cury);
-   }
-   return;
-   case '\b':
-   if (curx > 0) {
-   curx--;
+   /* Emulate AH=0eh (teletype output) */
+   switch(c) {
+   case '\a':
+   vidc_biosputchar(c);
+   return;
+   case '\r':
+   curx = 0;
+   curs_move(, , curx, cury);
+   return;
+   case '\n':
+   cury++;
+   if (cury > 24) {
+   scroll_up(1, fg_c, bg_c);
+   cury--;
+   } else {
+   curs_move(, , curx, cury);
+   }
+   return;
+   case '\b':
+   if (curx > 0) {
+   curx--;
+   curs_move(, , curx, cury);
+   /* write_char(' ', fg_c, bg_c); XXX 
destructive(!) */
+   return;
+   }
+   return;
+   default:
+   write_char(c, fg_c, bg_c);
+   curx++;
+   if (curx > 79) {
+   curx = 0;
+   cury++;
+ 

git: 4cddd20e1ea8 - main - loader/ofw: Style(9) pass over return statements

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4cddd20e1ea8b9c622c72edfad3e64f70e9d56a9

commit 4cddd20e1ea8b9c622c72edfad3e64f70e9d56a9
Author: Warner Losh 
AuthorDate: 2024-05-19 21:14:43 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:43 +

loader/ofw: Style(9) pass over return statements

Make these consistent. Some files weren't even consistent with
themselves. Make them all either return  (  ); or
return;

Sponsored by:   Netflix
---
 stand/libofw/devicename.c  |  4 ++--
 stand/libofw/ofw_console.c | 10 +-
 stand/libofw/ofw_copy.c|  8 
 stand/libofw/ofw_module.c  |  2 +-
 stand/libofw/ofw_net.c | 12 ++--
 stand/libofw/ofw_time.c|  4 ++--
 6 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c
index 5e3a789c13db..f6419632c6bc 100644
--- a/stand/libofw/devicename.c
+++ b/stand/libofw/devicename.c
@@ -101,12 +101,12 @@ ofw_common_parsedev(struct devdesc **dev, const char 
*devspec, const char **path
idev = malloc(sizeof(struct ofw_devdesc));
if (idev == NULL) {
printf("ofw_parsedev: malloc failed\n");
-   return ENOMEM;
+   return (ENOMEM);
};
strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1,
sizeof(idev->d_path)));
*dev = >dd;
if (path != NULL)
*path = rem_path;
-   return 0;
+   return (0);
 }
diff --git a/stand/libofw/ofw_console.c b/stand/libofw/ofw_console.c
index 4fbd43d3f612..75f9bfba0968 100644
--- a/stand/libofw/ofw_console.c
+++ b/stand/libofw/ofw_console.c
@@ -62,7 +62,7 @@ ofw_cons_probe(struct console *cp)
 static int
 ofw_cons_init(int arg)
 {
-   return 0;
+   return (0);
 }
 
 void
@@ -90,7 +90,7 @@ ofw_cons_getchar(void)
if (saved_char != -1) {
l = saved_char;
saved_char = -1;
-   return l;
+   return (l);
}
 
/* At least since version 4.0.0, QEMU became bug-compatible
@@ -109,12 +109,12 @@ ofw_cons_poll(void)
unsigned char ch;
 
if (saved_char != -1)
-   return 1;
+   return (1);
 
if (OF_read(stdin, , 1) > 0) {
saved_char = ch;
-   return 1;
+   return (1);
}
 
-   return 0;
+   return (0);
 }
diff --git a/stand/libofw/ofw_copy.c b/stand/libofw/ofw_copy.c
index b855a5b41d96..17a46fe4e480 100644
--- a/stand/libofw/ofw_copy.c
+++ b/stand/libofw/ofw_copy.c
@@ -119,14 +119,14 @@ ofw_copyin(const void *src, vm_offset_t dest, const 
size_t len)
 }
 
 bcopy(src, (void *)dest, len);
-return(len);
+return (len);
 }
 
 ssize_t
 ofw_copyout(const vm_offset_t src, void *dest, const size_t len)
 {
bcopy((void *)src, dest, len);
-   return(len);
+   return (len);
 }
 
 ssize_t
@@ -143,7 +143,7 @@ ofw_readin(readin_handle_t fd, vm_offset_t dest, const 
size_t len)
buf = malloc(chunk);
if (buf == NULL) {
printf("ofw_readin: buf malloc failed\n");
-   return(0);
+   return (0);
}
 
 if (ofw_mapmem(dest, len)) {
@@ -166,5 +166,5 @@ ofw_readin(readin_handle_t fd, vm_offset_t dest, const 
size_t len)
}
 
free(buf);
-   return(len - resid);
+   return (len - resid);
 }
diff --git a/stand/libofw/ofw_module.c b/stand/libofw/ofw_module.c
index 8d56f6debbb6..4c1fe9cd279d 100644
--- a/stand/libofw/ofw_module.c
+++ b/stand/libofw/ofw_module.c
@@ -42,5 +42,5 @@ int
 ofw_autoload(void)
 {
 /* XXX Call some machdep autoload routine? */
-return(0);
+return (0);
 }
diff --git a/stand/libofw/ofw_net.c b/stand/libofw/ofw_net.c
index b4bcb7a00fe2..3418216a9836 100644
--- a/stand/libofw/ofw_net.c
+++ b/stand/libofw/ofw_net.c
@@ -80,13 +80,13 @@ static void *dmabuf;
 static int
 ofwn_match(struct netif *nif, void *machdep_hint)
 {
-   return 1;
+   return (1);
 }
 
 static int
 ofwn_probe(struct netif *nif, void *machdep_hint)
 {
-   return 0;
+   return (0);
 }
 
 static ssize_t
@@ -123,7 +123,7 @@ ofwn_put(struct iodesc *desc, void *pkt, size_t len)
printf("netif_put: OF_write returned %d\n", rv);
 #endif
 
-   return rv;
+   return (rv);
 }
 
 static ssize_t
@@ -256,13 +256,13 @@ ofwn_getunit(const char *path)
for (i = 0; i < nofwninfo; i++) {
printf(">>> test =\t%s\n", ofwninfo[i].ofwn_path);
if (strcmp(path, ofwninfo[i].ofwn_path) == 0)
-   return i;
+   return (i);
 
if (strcmp(newpath, ofwninfo[i].ofwn_path) == 0)
-   return i;
+   return (i);
}
 
-   return -1;
+   return (-1);
 }
 #endif
 
diff --git a/stand/libofw/ofw_time.c b/stand/libofw/ofw_time.c

git: 3f012b9508c8 - main - loader: stlye(9) nit: Space between return and the value

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=3f012b9508c8a4d7874f114e76ebccd80c78e890

commit 3f012b9508c8a4d7874f114e76ebccd80c78e890
Author: Warner Losh 
AuthorDate: 2024-05-19 21:10:32 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:43 +

loader: stlye(9) nit: Space between return and the value

Sponsored by:   Netflix
---
 stand/i386/libi386/nullconsole.c | 6 +++---
 stand/i386/libi386/spinconsole.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/stand/i386/libi386/nullconsole.c b/stand/i386/libi386/nullconsole.c
index 1cd6cd096f27..2878512071ad 100644
--- a/stand/i386/libi386/nullconsole.c
+++ b/stand/i386/libi386/nullconsole.c
@@ -63,7 +63,7 @@ nullc_probe(struct console *cp)
 static int
 nullc_init(int arg)
 {
-   return(0);
+   return (0);
 }
 
 static void
@@ -74,11 +74,11 @@ nullc_putchar(int c)
 static int
 nullc_getchar(void)
 {
-   return(-1);
+   return (-1);
 }
 
 static int
 nullc_ischar(void)
 {
-   return(0);
+   return (0);
 }
diff --git a/stand/i386/libi386/spinconsole.c b/stand/i386/libi386/spinconsole.c
index 67561ff03bbd..d4c22bdbb1c3 100644
--- a/stand/i386/libi386/spinconsole.c
+++ b/stand/i386/libi386/spinconsole.c
@@ -71,7 +71,7 @@ static int
 spinc_init(int arg)
 {
 
-   return(parent->c_init(arg));
+   return (parent->c_init(arg));
 }
 
 static void
@@ -97,12 +97,12 @@ static int
 spinc_getchar(void)
 {
 
-   return(-1);
+   return (-1);
 }
 
 static int
 spinc_ischar(void)
 {
 
-   return(0);
+   return (0);
 }



git: 2d425b634f74 - main - loader: c_init returns 0 or 1

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=2d425b634f742ca7a803ab678ad9226607335161

commit 2d425b634f742ca7a803ab678ad9226607335161
Author: Warner Losh 
AuthorDate: 2024-05-19 21:08:40 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:42 +

loader: c_init returns 0 or 1

c_init returns 0 (success) or 1 (failure). Don't return other values.

Sponsored by:   Netflix
---
 stand/efi/libefi/eficom.c   | 4 ++--
 stand/i386/libi386/comconsole.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/stand/efi/libefi/eficom.c b/stand/efi/libefi/eficom.c
index d5f3f07e083f..f1ce14eb50f8 100644
--- a/stand/efi/libefi/eficom.c
+++ b/stand/efi/libefi/eficom.c
@@ -390,10 +390,10 @@ static int
 comc_init(int arg __unused)
 {
if (comc_setup())
-   return (CMD_OK);
+   return (0);
 
eficom.c_flags &= ~(C_ACTIVEIN | C_ACTIVEOUT);
-   return (CMD_ERROR);
+   return (1);
 }
 
 static void
diff --git a/stand/i386/libi386/comconsole.c b/stand/i386/libi386/comconsole.c
index b2d48b13a9f4..dc6bbcfe9806 100644
--- a/stand/i386/libi386/comconsole.c
+++ b/stand/i386/libi386/comconsole.c
@@ -140,8 +140,8 @@ comc_init(int arg)
 
if ((comconsole.c_flags & (C_PRESENTIN | C_PRESENTOUT)) ==
(C_PRESENTIN | C_PRESENTOUT))
-   return (CMD_OK);
-   return (CMD_ERROR);
+   return (0);
+   return (1);
 }
 
 static void



git: 125b181674e8 - main - userboot: Use C99 Initializers for each of the consoles here

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=125b181674e894baebfe463ed097305329427a2e

commit 125b181674e894baebfe463ed097305329427a2e
Author: Warner Losh 
AuthorDate: 2024-05-19 21:03:34 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:42 +

userboot: Use C99 Initializers for each of the consoles here

Sponsored by:   Netflix
---
 stand/userboot/userboot/userboot_cons.c | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/stand/userboot/userboot/userboot_cons.c 
b/stand/userboot/userboot/userboot_cons.c
index a905f1397232..26c89dc2a37e 100644
--- a/stand/userboot/userboot/userboot_cons.c
+++ b/stand/userboot/userboot/userboot_cons.c
@@ -42,14 +42,13 @@ static int userboot_cons_getchar(void);
 static int userboot_cons_poll(void);
 
 struct console userboot_console = {
-   "userboot",
-   "userboot",
-   0,
-   userboot_cons_probe,
-   userboot_cons_init,
-   userboot_cons_putchar,
-   userboot_cons_getchar,
-   userboot_cons_poll,
+   .c_name = "userboot",
+   .c_desc = "userboot",
+   .c_probe = userboot_cons_probe,
+   .c_init = userboot_cons_init,
+   .c_out = userboot_cons_putchar,
+   .c_in = userboot_cons_getchar,
+   .c_ready = userboot_cons_poll,
 };
 
 /*
@@ -57,14 +56,13 @@ struct console userboot_console = {
  * console to comconsole without resulting in an error
  */
 struct console userboot_comconsole = {
-   "comconsole",
-   "comconsole",
-   0,
-   userboot_comcons_probe,
-   userboot_comcons_init,
-   userboot_cons_putchar,
-   userboot_cons_getchar,
-   userboot_cons_poll,
+   .c_name = "comconsole",
+   .c_desc = "comconsole",
+   .c_probe = userboot_comcons_probe,
+   .c_init = userboot_comcons_init,
+   .c_out = userboot_cons_putchar,
+   .c_in = userboot_cons_getchar,
+   .c_ready = userboot_cons_poll,
 };
 
 static void



git: 1f180d0a404a - main - ofw: Use C99 initializers for the console struct

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=1f180d0a404a700889e40a91bbe21c20f310da4a

commit 1f180d0a404a700889e40a91bbe21c20f310da4a
Author: Warner Losh 
AuthorDate: 2024-05-19 21:01:23 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:42 +

ofw: Use C99 initializers for the console struct

Sponsored by:   Netflix
---
 stand/libofw/ofw_console.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/stand/libofw/ofw_console.c b/stand/libofw/ofw_console.c
index b0ead0aba198..4fbd43d3f612 100644
--- a/stand/libofw/ofw_console.c
+++ b/stand/libofw/ofw_console.c
@@ -41,14 +41,13 @@ static ihandle_t stdin;
 static ihandle_t stdout;
 
 struct console ofwconsole = {
-   "ofw",
-   "Open Firmware console",
-   0,
-   ofw_cons_probe,
-   ofw_cons_init,
-   ofw_cons_putchar,
-   ofw_cons_getchar,
-   ofw_cons_poll,
+   .c_cname = "ofw",
+   .c_desc = "Open Firmware console",
+   .c_probe = ofw_cons_probe,
+   .c_init = ofw_cons_init,
+   .c_out = ofw_cons_putchar,
+   .c_in = ofw_cons_getchar,
+   .c_ready = ofw_cons_poll,
 };
 
 static void



git: 6e28b4aa15e0 - main - uboot: Use c99 initializers for the console struct

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=6e28b4aa15e057f59c0e022094c3f82f3062c2a3

commit 6e28b4aa15e057f59c0e022094c3f82f3062c2a3
Author: Warner Losh 
AuthorDate: 2024-05-19 20:58:42 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:42 +

uboot: Use c99 initializers for the console struct

Sponsored by:   Netflix
---
 stand/uboot/uboot_console.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/stand/uboot/uboot_console.c b/stand/uboot/uboot_console.c
index 60d6ccaf4417..c02ba9aba5f0 100644
--- a/stand/uboot/uboot_console.c
+++ b/stand/uboot/uboot_console.c
@@ -37,14 +37,13 @@ static int uboot_cons_getchar(void);
 static int uboot_cons_poll(void);
 
 struct console uboot_console = {
-   "uboot",
-   "U-Boot console",
-   0,
-   uboot_cons_probe,
-   uboot_cons_init,
-   uboot_cons_putchar,
-   uboot_cons_getchar,
-   uboot_cons_poll,
+   .c_name = "uboot",
+   .c_desc = "U-Boot console",
+   .c_probe = uboot_cons_probe,
+   .c_init = uboot_cons_init,
+   .c_out = uboot_cons_putchar,
+   .c_int = uboot_cons_getchar,
+   .c_ready = uboot_cons_poll,
 };
 
 static void



git: b3551da9cd3d - main - efi_console: Use c99 initializers

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=b3551da9cd3dacbc7242c3be6fefe234784645fe

commit b3551da9cd3dacbc7242c3be6fefe234784645fe
Author: Warner Losh 
AuthorDate: 2024-05-19 20:57:16 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:42 +

efi_console: Use c99 initializers

Sponsored by:   Netflix
---
 stand/efi/libefi/efi_console.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/stand/efi/libefi/efi_console.c b/stand/efi/libefi/efi_console.c
index 4a3219ef3017..2e28cf1ec460 100644
--- a/stand/efi/libefi/efi_console.c
+++ b/stand/efi/libefi/efi_console.c
@@ -126,14 +126,14 @@ int efi_cons_poll(void);
 static void cons_draw_frame(teken_attr_t *);
 
 struct console efi_console = {
-   "efi",
-   "EFI console",
-   C_WIDEOUT,
-   efi_cons_probe,
-   efi_cons_init,
-   efi_cons_putchar,
-   efi_cons_getchar,
-   efi_cons_poll
+   .c_name = "efi",
+   .c_desc = "EFI console",
+   .c_flags = C_WIDEOUT,
+   .c_probe = efi_cons_probe,
+   .c_init = efi_cons_init,
+   .c_out = efi_cons_putchar,
+   .c_in = efi_cons_getchar,
+   .c_ready = efi_cons_poll
 };
 
 /*



git: 5e7b0cd93a95 - main - i386/nullconsole: Use C99 initializers

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5e7b0cd93a950033b1ab69f21a030ae39efc64f4

commit 5e7b0cd93a950033b1ab69f21a030ae39efc64f4
Author: Warner Losh 
AuthorDate: 2024-05-19 20:55:09 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:41 +

i386/nullconsole: Use C99 initializers

Sponsored by:   Netflix
---
 stand/i386/libi386/nullconsole.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/stand/i386/libi386/nullconsole.c b/stand/i386/libi386/nullconsole.c
index b4ffd3e30789..1cd6cd096f27 100644
--- a/stand/i386/libi386/nullconsole.c
+++ b/stand/i386/libi386/nullconsole.c
@@ -45,14 +45,13 @@ static int  nullc_getchar(void);
 static int nullc_ischar(void);
 
 struct console nullconsole = {
-   "nullconsole",
-   "null port",
-   0,
-   nullc_probe,
-   nullc_init,
-   nullc_putchar,
-   nullc_getchar,
-   nullc_ischar
+   .c_name = "nullconsole",
+   .c_desc = "null port",
+   .c_probe = nullc_probe,
+   .c_init = nullc_init,
+   .c_out = nullc_putchar,
+   .c_in = nullc_getchar,
+   .c_ready = nullc_ischar
 };
 
 static void



git: 803060b21799 - main - i386/spinconsole: Use C99 initializers

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=803060b21799664ba2fd8d9d9890aaaf57421a5f

commit 803060b21799664ba2fd8d9d9890aaaf57421a5f
Author: Warner Losh 
AuthorDate: 2024-05-19 20:52:53 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:41 +

i386/spinconsole: Use C99 initializers

Sponsored by:   Netflix
---
 stand/i386/libi386/spinconsole.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/stand/i386/libi386/spinconsole.c b/stand/i386/libi386/spinconsole.c
index 156eaf35e1c0..67561ff03bbd 100644
--- a/stand/i386/libi386/spinconsole.c
+++ b/stand/i386/libi386/spinconsole.c
@@ -47,14 +47,13 @@ static int  spinc_ischar(void);
 extern struct console *consoles[];
 
 struct console spinconsole = {
-   "spinconsole",
-   "spin port",
-   0,
-   spinc_probe,
-   spinc_init,
-   spinc_putchar,
-   spinc_getchar,
-   spinc_ischar
+   .c_name = "spinconsole",
+   .c_desc = "spin port",
+   .c_probe = spinc_probe,
+   .c_init = spinc_init,
+   .c_out = spinc_putchar,
+   .c_in = spinc_getchar,
+   .c_ready = spinc_ischar
 };
 
 static struct console *parent = NULL;



git: a578e2b896d9 - main - boot/i386: Use C99 initializer for textvidc

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a578e2b896d9e6803a830c99fb486fa60ceac33f

commit a578e2b896d9e6803a830c99fb486fa60ceac33f
Author: Warner Losh 
AuthorDate: 2024-05-19 20:49:02 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:41 +

boot/i386: Use C99 initializer for textvidc

Sponsored by:   Netflix
---
 stand/i386/libi386/textvidc.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/stand/i386/libi386/textvidc.c b/stand/i386/libi386/textvidc.c
index 4b79f9fc66b3..75d498930119 100644
--- a/stand/i386/libi386/textvidc.c
+++ b/stand/i386/libi386/textvidc.c
@@ -70,14 +70,13 @@ static int  esc;
 
 
 struct console textvidc = {
-"vidconsole",
-"internal video/keyboard",
-0,
-vidc_probe,
-vidc_init,
-vidc_putchar,
-vidc_getchar,
-vidc_ischar
+   .c_name = "vidconsole",
+   .c_desc = "internal video/keyboard",
+   .c_probe = vidc_probe,
+   .c_init = vidc_init,
+   .c_out = vidc_putchar,
+   .c_in = vidc_getchar,
+   .c_ready = vidc_ischar
 };
 
 static void



git: f989ebd4dea2 - main - kboot: Use C99 initialiers for hostconsole.

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f989ebd4dea2ad45f3dd491d86f821a524a0360f

commit f989ebd4dea2ad45f3dd491d86f821a524a0360f
Author: Warner Losh 
AuthorDate: 2024-05-19 20:47:20 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:41 +

kboot: Use C99 initialiers for hostconsole.

Sponsored by:   Netflix
---
 stand/kboot/kboot/hostcons.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/stand/kboot/kboot/hostcons.c b/stand/kboot/kboot/hostcons.c
index 114188adcff2..9c09a2721891 100644
--- a/stand/kboot/kboot/hostcons.c
+++ b/stand/kboot/kboot/hostcons.c
@@ -35,14 +35,13 @@ static int hostcons_getchar(void);
 static int hostcons_poll(void);
 
 struct console hostconsole = {
-   "host",
-   "Host Console",
-   0,
-   hostcons_probe,
-   hostcons_init,
-   hostcons_putchar,
-   hostcons_getchar,
-   hostcons_poll,
+   .c_name = "host",
+   .c_desc = "Host Console",
+   .c_probe = hostcons_probe,
+   .c_init = hostcons_init,
+   .c_out = hostcons_putchar,
+   .c_in = hostcons_getchar,
+   .c_ready = hostcons_poll,
 };
 
 static struct host_termios old_settings;



git: 0111f09ca670 - main - kboot: Initialize hostfs_root sooner (and remove kboot.conf)

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0111f09ca67070271e43655db2e4989cf2d64f88

commit 0111f09ca67070271e43655db2e4989cf2d64f88
Author: Warner Losh 
AuthorDate: 2024-05-19 17:05:48 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:41 +

kboot: Initialize hostfs_root sooner (and remove kboot.conf)

Move the initialization of hostfs_root to be a bit sooner. While it
doesn't matter for the default case, we may want to use hostfs files
sooner.

Also, while we're here, remove kboot.conf. It duplicates the command
line and has proven difficult to use. It will be replaced by an early
script that can influence the state of the boot loader before we select
a device to boot from (including strongly suggesting which one to boot
from).

Sponsored by:   Netflix
---
 stand/kboot/kboot/main.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/stand/kboot/kboot/main.c b/stand/kboot/kboot/main.c
index ed5cad45..994df1ec9fa1 100644
--- a/stand/kboot/kboot/main.c
+++ b/stand/kboot/kboot/main.c
@@ -357,17 +357,17 @@ main(int argc, const char **argv)
/* Parse the command line args -- ignoring for now the console 
selection */
parse_args(argc, argv);
 
-   parse_file("host:/kboot.conf");
+   hostfs_root = getenv("hostfs_root");
+   if (hostfs_root == NULL)
+   hostfs_root = "/";
 
/* Initialize all the devices */
devinit();
 
+   /* Figure out where we're booting from */
bootdev = getenv("bootdev");
if (bootdev == NULL)
bootdev = hostdisk_gen_probe();
-   hostfs_root = getenv("hostfs_root");
-   if (hostfs_root == NULL)
-   hostfs_root = "/";
 #if defined(LOADER_ZFS_SUPPORT)
if (bootdev == NULL || strcmp(bootdev, "zfs:") == 0) {
/*



git: 68344c9c6c69 - main - loader: separate lang init from scripting init

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=68344c9c6c69fc604b402eee420285356f7a677f

commit 68344c9c6c69fc604b402eee420285356f7a677f
Author: Warner Losh 
AuthorDate: 2024-05-19 17:48:14 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:40 +

loader: separate lang init from scripting init

Create interp_preinit() to initialize the scripting language to run
scripts. Make sure you can call it multiple times, but only the first
one has effect, After it's call, you can run scripts in the scripting
language. At the moment, no functional change.

Sponsored by:   Netflix
---
 stand/common/bootstrap.h |  3 ++-
 stand/common/interp.c|  1 +
 stand/common/interp_forth.c  | 13 +++--
 stand/common/interp_lua.c| 23 +--
 stand/common/interp_simple.c |  5 +
 5 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h
index b7d6e538f9be..79ce0b023b7a 100644
--- a/stand/common/bootstrap.h
+++ b/stand/common/bootstrap.h
@@ -54,7 +54,8 @@ bool  interp_has_builtin_cmd(const char *cmd);
 
 /* Called by interp.c for interp_*.c embedded interpreters */
 intinterp_include(const char *);   /* Execute commands from filename */
-void   interp_init(void);  /* Initialize interpreater */
+void   interp_preinit(void);   /* Initialize interpreater execution 
engine */
+void   interp_init(void);  /* Initialize interpreater and run main 
script */
 intinterp_run(const char *);   /* Run a single command */
 
 /* interp_backslash.c */
diff --git a/stand/common/interp.c b/stand/common/interp.c
index c6ac01ea099b..5d20822e037d 100644
--- a/stand/common/interp.c
+++ b/stand/common/interp.c
@@ -60,6 +60,7 @@ interact(void)
 * we need to switch interpreters.
 */
interp_identifier = bootprog_interp;
+   interp_preinit();
interp_init();
 
printf("\n");
diff --git a/stand/common/interp_forth.c b/stand/common/interp_forth.c
index 854addb22d5c..388a20e319b3 100644
--- a/stand/common/interp_forth.c
+++ b/stand/common/interp_forth.c
@@ -337,12 +337,21 @@ bf_run(const char *line)
return (result);
 }
 
+static bool preinit_run = false;
+
 void
-interp_init(void)
+interp_preinit(void)
 {
-
+   if (preinit_run)
+   return;
setenv("script.lang", "forth", 1);
bf_init();
+   preinit_run = true;
+}
+
+void
+interp_init(void)
+{
/* Read our default configuration. */
interp_include("/boot/loader.rc");
 }
diff --git a/stand/common/interp_lua.c b/stand/common/interp_lua.c
index aa759aa99ec1..2a61bb9d04af 100644
--- a/stand/common/interp_lua.c
+++ b/stand/common/interp_lua.c
@@ -96,17 +96,21 @@ static const luaL_Reg loadedlibs[] = {
   {NULL, NULL}
 };
 
+static bool preinit_done = false;
+
 void
-interp_init(void)
+interp_preinit(void)
 {
lua_State *luap;
struct interp_lua_softc *softc = _softc;
-   const char *filename;
const luaL_Reg *lib;
lua_init_md_t **fnpp;
 
TSENTER();
 
+   if (preinit_done)
+   return;
+
setenv("script.lang", "lua", 1);
LDBG("creating context");
 
@@ -126,6 +130,21 @@ interp_init(void)
LUA_FOREACH_SET(fnpp)
(*fnpp)(luap);
 
+   preinit_done = true;
+
+   TSEXIT();
+}
+
+void
+interp_init(void)
+{
+   lua_State *luap;
+   struct interp_lua_softc *softc = _softc;
+   const char *filename;
+
+   TSENTER();
+
+   luap = softc->luap;
filename = getenv("loader_lua");
if (filename == NULL)
filename = LOADER_LUA;
diff --git a/stand/common/interp_simple.c b/stand/common/interp_simple.c
index d675da0aa61e..437739a3bcc4 100644
--- a/stand/common/interp_simple.c
+++ b/stand/common/interp_simple.c
@@ -34,6 +34,11 @@
 
 INTERP_DEFINE("simp");
 
+void
+interp_preinit(void)
+{
+}
+
 void
 interp_init(void)
 {



git: 1d7bdae9ca3c - main - kboot: Move console, acpi and smbios init

2024-05-19 Thread Warner Losh
The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=1d7bdae9ca3ca821e93386d85e87de491471cad7

commit 1d7bdae9ca3ca821e93386d85e87de491471cad7
Author: Warner Losh 
AuthorDate: 2024-05-19 16:41:52 +
Commit: Warner Losh 
CommitDate: 2024-05-20 04:05:40 +

kboot: Move console, acpi and smbios init

Move the console probing to as early as possible. There's no real
support for anything but hostcons, and setting it up early will show
other error messages.

ACPI and SMBIOS probing can be done just after we have the console, so
move it there. This allows other parts of the early code to use info
from that, as well as overriding and env vars set by these things on the
command line (smbios data may be wrong during initial development phases
as the automated way to populate per-board data may not be established,
etc).

Sponsored by:   Netflix
---
 stand/kboot/kboot/main.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/stand/kboot/kboot/main.c b/stand/kboot/kboot/main.c
index e57446baa47d..ed5cad45 100644
--- a/stand/kboot/kboot/main.c
+++ b/stand/kboot/kboot/main.c
@@ -342,16 +342,23 @@ main(int argc, const char **argv)
heapbase = host_getmem(heapsize);
setheap(heapbase, heapbase + heapsize);
 
+   /*
+* Set up console so we get error messages.
+*/
+   cons_probe();
+
+   /*
+* Find acpi and smbios, if they exists. This allows command line and
+* later scripts to override if necessary.
+*/
+   find_acpi();
+   find_smbios();
+
/* Parse the command line args -- ignoring for now the console 
selection */
parse_args(argc, argv);
 
parse_file("host:/kboot.conf");
 
-   /*
-* Set up console.
-*/
-   cons_probe();
-
/* Initialize all the devices */
devinit();
 
@@ -394,13 +401,6 @@ main(int argc, const char **argv)
memory_limits();
enumerate_memory_arch();
 
-   /*
-* Find acpi, if it exists
-*/
-   find_acpi();
-
-   find_smbios();
-
interact(); /* doesn't return */
 
return (0);



git: 68c890b4433d - main - linux(4): Add const qualifier to the value parameter of function handle_string()

2024-05-19 Thread Zhenlei Huang
The branch main has been updated by zlei:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=68c890b4433d3655c7df91cc43f89f4d6a8b35e4

commit 68c890b4433d3655c7df91cc43f89f4d6a8b35e4
Author: Zhenlei Huang 
AuthorDate: 2024-05-20 04:02:33 +
Commit: Zhenlei Huang 
CommitDate: 2024-05-20 04:02:33 +

linux(4): Add const qualifier to the value parameter of function 
handle_string()

The content that `value` point to is not going to be altered by function
handle_string().

MFC after:  1 week
---
 sys/compat/linux/linux_sysctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/compat/linux/linux_sysctl.c b/sys/compat/linux/linux_sysctl.c
index 65c64a7ba563..97341c051af7 100644
--- a/sys/compat/linux/linux_sysctl.c
+++ b/sys/compat/linux/linux_sysctl.c
@@ -74,7 +74,7 @@ LIN_SDT_PROBE_DEFINE1(sysctl, linux_sysctl, 
unsupported_sysctl, "char *");
 
 #ifdef LINUX_LEGACY_SYSCALLS
 static int
-handle_string(struct l___sysctl_args *la, char *value)
+handle_string(struct l___sysctl_args *la, const char *value)
 {
int error;
 



git: 92f2a4c820fe - main - compat_freebsd4: Add const qualifier to the local variable s inside function freebsd4_uname()

2024-05-19 Thread Zhenlei Huang
The branch main has been updated by zlei:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=92f2a4c820fea9efcb6ee6a7029495c8152958c1

commit 92f2a4c820fea9efcb6ee6a7029495c8152958c1
Author: Zhenlei Huang 
AuthorDate: 2024-05-20 04:02:32 +
Commit: Zhenlei Huang 
CommitDate: 2024-05-20 04:02:32 +

compat_freebsd4: Add const qualifier to the local variable s inside 
function freebsd4_uname()

This local variable s is for iterating characters of global variable
`version`. The content of `version` is not going to be altered by
function freebsd4_uname().

MFC after:  1 week
---
 sys/kern/kern_xxx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c
index 46155cf6a73e..fb76d420df7c 100644
--- a/sys/kern/kern_xxx.c
+++ b/sys/kern/kern_xxx.c
@@ -315,7 +315,8 @@ freebsd4_uname(struct thread *td, struct 
freebsd4_uname_args *uap)
 {
int name[2], error;
size_t len;
-   char *s, *us;
+   const char *s;
+   char *us;
 
name[0] = CTL_KERN;
name[1] = KERN_OSTYPE;



git: 6cba29c09a96 - main - acpidump IVRS table format: change 'IOMMUId' into 'IOMMU DeviceId'

2024-05-19 Thread Konstantin Belousov
The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=6cba29c09a966be33b0958f912a7c03d92b926b8

commit 6cba29c09a966be33b0958f912a7c03d92b926b8
Author: Konstantin Belousov 
AuthorDate: 2024-05-19 23:01:43 +
Commit: Konstantin Belousov 
CommitDate: 2024-05-19 23:04:45 +

acpidump IVRS table format: change 'IOMMUId' into 'IOMMU DeviceId'

and apply the consistent format for device ids used in other IVRS
elements.  The field seems to be the PCI Device ID of the IOMMU itself,
instead of an abstract unit ID.

Sponsored by:   Advanced Micro Devices (AMD)
Sponsored by:   The FreeBSD Foundation
MFC after:  1 week
---
 usr.sbin/acpi/acpidump/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c
index 0cc3f76ac018..fc2e8cb82c49 100644
--- a/usr.sbin/acpi/acpidump/acpi.c
+++ b/usr.sbin/acpi/acpidump/acpi.c
@@ -1504,7 +1504,7 @@ acpi_handle_dmar(ACPI_TABLE_HEADER *sdp)
 static void
 acpi_handle_ivrs_ivhd_header(ACPI_IVRS_HEADER *addr)
 {
-   printf("\n\tIVHD Type=%#x IOMMUId=%x\n\tFlags=",
+   printf("\n\tIVHD Type=%#x IOMMU DeviceId=%#06x\n\tFlags=",
addr->Type, addr->DeviceId);
 #define PRINTFLAG(flag, name) printflag(addr->Flags, flag, #name)
PRINTFLAG(ACPI_IVHD_TT_ENABLE, HtTunEn);



git: 4f77144279f2 - main - arm64 pmap: eliminate a redundant variable

2024-05-19 Thread Alan Cox
The branch main has been updated by alc:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4f77144279f210ce65d77c13470c6363c3ce3c57

commit 4f77144279f210ce65d77c13470c6363c3ce3c57
Author: Alan Cox 
AuthorDate: 2024-05-19 19:22:53 +
Commit: Alan Cox 
CommitDate: 2024-05-19 19:33:19 +

arm64 pmap: eliminate a redundant variable

Moreover, if we attempt an L2 promotion on the kernel pmap from
pmap_enter_quick_locked(), this change eliminates the recomputation of
the L2 entry's address.

MFC after:  1 week
---
 sys/arm64/arm64/pmap.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index a6056a5edfc2..269513589d78 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -5848,7 +5848,6 @@ static vm_page_t
 pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, vm_page_t m,
 vm_prot_t prot, vm_page_t mpte, struct rwlock **lockp)
 {
-   pd_entry_t *pde;
pt_entry_t *l1, *l2, *l3, l3_val;
vm_paddr_t pa;
int lvl;
@@ -5913,13 +5912,13 @@ pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, 
vm_page_t m,
l3 = [pmap_l3_index(va)];
} else {
mpte = NULL;
-   pde = pmap_pde(kernel_pmap, va, );
-   KASSERT(pde != NULL,
+   l2 = pmap_pde(kernel_pmap, va, );
+   KASSERT(l2 != NULL,
("pmap_enter_quick_locked: Invalid page entry, va: 0x%lx",
 va));
KASSERT(lvl == 2,
("pmap_enter_quick_locked: Invalid level %d", lvl));
-   l3 = pmap_l2_to_l3(pde, va);
+   l3 = pmap_l2_to_l3(l2, va);
}
 
/*



Re: git: be04fec42638 - main - Import _FORTIFY_SOURCE implementation from NetBSD

2024-05-19 Thread Shawn Webb
I did not know a battle was even being fought. :-)

I'd like to give a little hypothetical as to why I think these
features are complementary to each other.

The primary goal of SafeStack is to protect the control flow. This
means putting spillable data in a separate stack, named the unsafe
stack. Spilling one buffer into another is (usually) not as bad as
spilling onto the return address pointer on the stack. SafeStack does
not attempt to prevent spillage.

The primary goal of the SSP canary is also to protect control flow.
However, in some cases, the check may be too late. If a function
pointer sits adjacent to a spilled buffer, and the function pointer is
called after the buffer is overflowed, the attacker gains arbitrary
code execution.

One feature critical to _FORTIFY_SOURCE is better bounds checking,
both at compile time and run time.

Let's say, hypothetically, that two buffers are created and sit
adjacent to each other. SafeStack put these two buffers on the unsafe
stack. The second buffer contains authentication and authorization
data. By overflowing into the second buffer, the attacker can gain
new privileges. If the buffer contains authentication data, perhaps
the attacker can (from this point forward) steal the session from
another user. If the buffer contains authorization data, perhaps the
attacker can (from this point forward) perform privileged operations.

This is where _FORTIFY_SOURCE comes in. If _FORTIFY_SOURCE can prevent
the overflow from happening, the attacker cannot steal sessions or
perform privileged operations.

I intentionally skipped over SSP in this hypothetical. In this
particular case, trying to protect the return address pointer saved on
the stack is moot. SSP is still useful, but not for this particular
hypothetical.

I hope this makes sense.

Thanks,

-- 
Shawn Webb
Cofounder / Security Engineer
HardenedBSD

Tor-ified Signal: +1 303-901-1600 / shawn_webb_opsec.50
https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/raw/master/Shawn_Webb/03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc

On Sun, May 19, 2024 at 02:47:22PM +, Pedro Giffuni wrote:
>  Hmm... well.
> In all honesty I understand I am doomed to lose this battle :).FORTIFY_SOURCE 
> is in linux and in Apple and that weights enough that it had to find it's way 
> to FreeBSD sooner or later. Plus I am just not much involved in FreeBSD or 
> OSs anymore so I don't feel like stopping other people from doing development.
> best of lucks!
> Pedro.
> ps. Just for the reference, the Google guys did develop a document on how 
> they implemented this for clang on bionic:https://goo.gl/8HS2dW
> 
> On Sunday, May 19, 2024 at 12:13:00 AM GMT-5, Kyle Evans 
>  wrote:  
>  
>  On 5/18/24 23:39, Pedro Giffuni wrote:
> > FWIW .. and let me be clear I haven't worked on this in ages and I am 
> > not planning to retake this either...
> > 
> > clang just couldn't do the static  fortify_source checks  due to the way 
> > llvm uses an intermediate representation; the size just couldn't be 
> > handled in the preprocessor. Google did spend some time adding extra 
> > attributes to clang to improve the debugging and you can see that 
> > implemented in bionic libc but that was it. musl didn't even try.
> > 
> 
> Admittedly, I have no idea what you're talking about here; none of this 
> implementation requires any knowledge of anything at preproc time. 
> __builtin_object_size() does the right thing, and the typically 
> performance critical string/memory ops use __builtin___foo_chk() that do 
> successfully get optimized away in the common case to the underlying 
> foo() call.  This all works very well with clang, I haven't tested it 
> under GCC but, as you've noted, would assume that it works at least as well.
> 
> > fortify_source does replace some key libc functions with memory checking 
> > alternatives and that turns out to be annoying when debugging. In a way 
> > it breaks that principle C programmers once had, where developers are 
> > expected to know what they are doing, and if the error is caught at 
> > runtime by the stack protector anyways it ends up being redundant.
> > > One more thing about the static checks. Most of the linux distributions
> > out there indeed have built their software packages with GCC and 
> > fortify_source >=2. As a consequence, when we ran an exp-run on the 
> > ports tree (with GCC), fortify_source didn't find anything: it was 
> > basically a waste of time.
> > 
> > Another reason for not setting it by default is performance. And here I 
> > answer Shawn's comment on why not enable stack-protector-all and 
> > safestack and fortify_source at the same time: running unnecessary 
> > checks over and over again wastes energy and can have some performance 
> > hit. The later may seem negligible in modern processors, but why do them 
> > if they bring no benefit? (No need to answer ... just left as food for 
> > thought)
> > 
> > Pedro.
> > 
> > On Saturday, May 18, 2024 at 09:08:52 PM GMT-5, 

git: 3cc1b35bc1bd - main - vfs_getopt(9): fix typo

2024-05-19 Thread Alan Somers
The branch main has been updated by asomers:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=3cc1b35bc1bdcdee279b3ee7d0e0946b684df898

commit 3cc1b35bc1bdcdee279b3ee7d0e0946b684df898
Author: Alan Somers 
AuthorDate: 2024-05-19 15:49:03 +
Commit: Alan Somers 
CommitDate: 2024-05-19 15:49:03 +

vfs_getopt(9): fix typo

[skip ci]

Reported by:Claudiu 
MFC after:  2 weeks
---
 share/man/man9/vfs_getopt.9 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/share/man/man9/vfs_getopt.9 b/share/man/man9/vfs_getopt.9
index 0e68655f540f..ff0f027314c7 100644
--- a/share/man/man9/vfs_getopt.9
+++ b/share/man/man9/vfs_getopt.9
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 .\" DAMAGE.
 .\"
-.Dd July 31, 2011
+.Dd May 19, 2024
 .Dt VFS_GETOPT 9
 .Os
 .Sh NAME
@@ -46,7 +46,7 @@
 .Fa "struct vfsoptlist *opts" "const char *name" "void **buf" "int *len"
 .Fc
 .Ft "char *"
-.Fn vfs_getops "struct vfsoptlist *opts" "const char *name" "int *error"
+.Fn vfs_getopts "struct vfsoptlist *opts" "const char *name" "int *error"
 .Ft int
 .Fo vfs_flagopt
 .Fa "struct vfsoptlist *opts" "const char *name" "uint64_t *flags" "uint64_t 
flag"
@@ -177,7 +177,7 @@ function returns 0 if the option was found; otherwise,
 is returned.
 .Pp
 The
-.Fn vfs_getops
+.Fn vfs_getopts
 function returns the specified option if it is found, and is
 .Dv NUL
 terminated.



Re: git: be04fec42638 - main - Import _FORTIFY_SOURCE implementation from NetBSD

2024-05-19 Thread Pedro Giffuni
 Hmm... well.
In all honesty I understand I am doomed to lose this battle :).FORTIFY_SOURCE 
is in linux and in Apple and that weights enough that it had to find it's way 
to FreeBSD sooner or later. Plus I am just not much involved in FreeBSD or OSs 
anymore so I don't feel like stopping other people from doing development.
best of lucks!
Pedro.
ps. Just for the reference, the Google guys did develop a document on how they 
implemented this for clang on bionic:https://goo.gl/8HS2dW

On Sunday, May 19, 2024 at 12:13:00 AM GMT-5, Kyle Evans 
 wrote:  
 
 On 5/18/24 23:39, Pedro Giffuni wrote:
> FWIW .. and let me be clear I haven't worked on this in ages and I am 
> not planning to retake this either...
> 
> clang just couldn't do the static  fortify_source checks  due to the way 
> llvm uses an intermediate representation; the size just couldn't be 
> handled in the preprocessor. Google did spend some time adding extra 
> attributes to clang to improve the debugging and you can see that 
> implemented in bionic libc but that was it. musl didn't even try.
> 

Admittedly, I have no idea what you're talking about here; none of this 
implementation requires any knowledge of anything at preproc time. 
__builtin_object_size() does the right thing, and the typically 
performance critical string/memory ops use __builtin___foo_chk() that do 
successfully get optimized away in the common case to the underlying 
foo() call.  This all works very well with clang, I haven't tested it 
under GCC but, as you've noted, would assume that it works at least as well.

> fortify_source does replace some key libc functions with memory checking 
> alternatives and that turns out to be annoying when debugging. In a way 
> it breaks that principle C programmers once had, where developers are 
> expected to know what they are doing, and if the error is caught at 
> runtime by the stack protector anyways it ends up being redundant.
> > One more thing about the static checks. Most of the linux distributions
> out there indeed have built their software packages with GCC and 
> fortify_source >=2. As a consequence, when we ran an exp-run on the 
> ports tree (with GCC), fortify_source didn't find anything: it was 
> basically a waste of time.
> 
> Another reason for not setting it by default is performance. And here I 
> answer Shawn's comment on why not enable stack-protector-all and 
> safestack and fortify_source at the same time: running unnecessary 
> checks over and over again wastes energy and can have some performance 
> hit. The later may seem negligible in modern processors, but why do them 
> if they bring no benefit? (No need to answer ... just left as food for 
> thought)
> 
> Pedro.
> 
> On Saturday, May 18, 2024 at 09:08:52 PM GMT-5, Kyle Evans 
>  wrote:
> 
> 
> 
> 
> On 5/18/24 20:09, Pedro Giffuni wrote:
>  > (sorry for top posting .. my mailer just sucks)
>  > Hi;
>  >
>  > I used to like the limited static checking FORTIFY_SOURCE provides and
>  > when I ran it over FreeBSD it did find a couple of minor issues. It only
>  > works for GCC though.
>  >
> 
> I don't think this is particularly true anymore; I haven't found a case
> yet where __builtin_object_size(3) doesn't give me the correct size
> while GCC did.  I'd welcome counter-examples here, though -- we have
> funding to both finish the project (widen the _FORTIFY_SOURCE net to
> more of libc/libsys) and add tests to demonstrate that it's both
> functional and correct.  It would be useful to also document
> deficiencies in the tests.
> 
>  > I guess it doesn't really hurt to have FORTIFY_SOURCE around and NetBSD
>  > had the least intrusive implementation the last time I checked but I
>  > would certainly request it should never be activated by default,
>  > specially with clang. The GCC version has seen more development on glibc
>  > but I still think its a dead end.
>  >
> 
> I don't see a compelling reason to avoid enabling it by default; see
> above, the functionality that we need in clang appears to be just fine
> (and, iirc, was also fine when I checked at the beginning of working on
> this in 2021) and it provides useful
> 
>  > What I would like to see working on FreeBSD is Safestack as a
>  > replacement for the stack protector, which we were so very slow to adopt
>  > even when it was originally developed in FreeBSD. I think other projects
>  > based on FreeBSD (Chimera and hardenedBSD) have been using it but I
>  > don't know the details.
>  >
> 
> No comment there, though I think Shawn Webb / HardenedBSD had been
> playing around with SafeStack (and might have enabled it? I haven't
> actually looked in a while now).
> 
>  > This is just all my $0.02
>  >
>  > Pedro.
> 
> Thanks,
> 
> Kyle Evans
> 
>  >
>  > On Saturday, May 18, 2024 at 05:54:42 PM GMT-5, Kyle Evans
>  > mailto:kaev...@fastmail.com>> wrote:
>  >
>  >
>  >
>  >
>  > On May 18, 2024 13:42, Pedro Giffuni  > wrote:
>  >
>  >    Oh no .. please not...
>  >
>  

Re: Re: git: be04fec42638 - main - Import _FORTIFY_SOURCE implementation from NetBSD

2024-05-19 Thread Pedro Giffuni
 For the record ...
When I was working on this, the default compiler on FreeBSD was still GCC 42 
and the static checks worked fine with it but not on clang. The runtime checks 
worked fine on both.
Pedro.
On Sunday, May 19, 2024 at 12:11:15 AM GMT-5, Jörg Sonnenberger 
 wrote:  
 
  
On Sunday, May 19, 2024 6:39:59 AM GMT+2 Pedro Giffuni wrote:

>  FWIW .. and let me be clear I haven't worked on this in ages and I am not 
>planning to retake this either...

> clang just couldn't do the static  fortify_source checks  due to the way llvm 
> uses an intermediate representation; the size just couldn't be handled in the 
> preprocessor.


That hasn't been true for a long time. __builtin_object_size is only

folded in the frontend if it absolutely has to because the context

requires an Integer Constant Expression, otherwise it is folded only

if the answer is definite. In all other cases it is left for the IR passes to

lower.


> fortify_source does replace some key libc functions with memory checking 
> alternatives and that turns out to be annoying when debugging.


Since the wrapper functions are always_inline, they are pretty much invisible 
to debuggers.


Joerg
  

git: 838d5ae6d82a - main - geli: fix indentation

2024-05-19 Thread Mariusz Zaborski
The branch main has been updated by oshogbo:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=838d5ae6d82a604e3f3338273b24e476a4eabb39

commit 838d5ae6d82a604e3f3338273b24e476a4eabb39
Author: Mariusz Zaborski 
AuthorDate: 2024-05-19 13:37:07 +
Commit: Mariusz Zaborski 
CommitDate: 2024-05-19 13:37:07 +

geli: fix indentation

no functional changes
---
 sys/geom/eli/g_eli.c | 252 +--
 1 file changed, 126 insertions(+), 126 deletions(-)

diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c
index ddb148ebd5db..a9f356299a8d 100644
--- a/sys/geom/eli/g_eli.c
+++ b/sys/geom/eli/g_eli.c
@@ -172,32 +172,32 @@ static void
 zero_boot_passcache(void)
 {
 
-explicit_bzero(cached_passphrase, sizeof(cached_passphrase));
+   explicit_bzero(cached_passphrase, sizeof(cached_passphrase));
 }
 
 static void
 zero_geli_intake_keys(void)
 {
-struct keybuf *keybuf;
-int i;
-
-if ((keybuf = get_keybuf()) != NULL) {
-/* Scan the key buffer, clear all GELI keys. */
-for (i = 0; i < keybuf->kb_nents; i++) {
- if (keybuf->kb_ents[i].ke_type == KEYBUF_TYPE_GELI) {
- explicit_bzero(keybuf->kb_ents[i].ke_data,
- sizeof(keybuf->kb_ents[i].ke_data));
- keybuf->kb_ents[i].ke_type = KEYBUF_TYPE_NONE;
- }
-}
-}
+   struct keybuf *keybuf;
+   int i;
+
+   if ((keybuf = get_keybuf()) != NULL) {
+   /* Scan the key buffer, clear all GELI keys. */
+   for (i = 0; i < keybuf->kb_nents; i++) {
+if (keybuf->kb_ents[i].ke_type == KEYBUF_TYPE_GELI) {
+   explicit_bzero(keybuf->kb_ents[i].ke_data,
+   sizeof(keybuf->kb_ents[i].ke_data));
+   keybuf->kb_ents[i].ke_type = KEYBUF_TYPE_NONE;
+   }
+   }
+   }
 }
 
 static void
 zero_intake_passcache(void *dummy)
 {
-zero_boot_passcache();
-zero_geli_intake_keys();
+   zero_boot_passcache();
+   zero_geli_intake_keys();
 }
 EVENTHANDLER_DEFINE(mountroot, zero_intake_passcache, NULL, 0);
 
@@ -269,7 +269,7 @@ g_eli_crypto_rerun(struct cryptop *crp)
 static void
 g_eli_getattr_done(struct bio *bp)
 {
-   if (bp->bio_error == 0 && 
+   if (bp->bio_error == 0 &&
!strcmp(bp->bio_attribute, "GEOM::physpath")) {
strlcat(bp->bio_data, "/eli", bp->bio_length);
}
@@ -891,8 +891,8 @@ g_eli_init_uma(void)
 * likely to see.
 */
g_eli_alloc_sz = roundup2((PAGE_SIZE + sizeof(int) +
-G_ELI_AUTH_SECKEYLEN) * nsw_cluster_max +
-sizeof(uintptr_t), PAGE_SIZE);
+   G_ELI_AUTH_SECKEYLEN) * nsw_cluster_max +
+   sizeof(uintptr_t), PAGE_SIZE);
 
g_eli_uma = uma_zcreate("GELI buffers", g_eli_alloc_sz,
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
@@ -1327,7 +1327,7 @@ g_eli_taste(struct g_class *mp, struct g_provider *pp, 
int flags __unused)
u_char key[G_ELI_USERKEYLEN], mkey[G_ELI_DATAIVKEYLEN];
u_int i, nkey, nkeyfiles, tries, showpass;
int error;
-struct keybuf *keybuf;
+   struct keybuf *keybuf;
 
g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name);
g_topology_assert();
@@ -1372,116 +1372,116 @@ g_eli_taste(struct g_class *mp, struct g_provider 
*pp, int flags __unused)
tries = g_eli_tries;
}
 
-if ((keybuf = get_keybuf()) != NULL) {
-/* Scan the key buffer, try all GELI keys. */
-for (i = 0; i < keybuf->kb_nents; i++) {
- if (keybuf->kb_ents[i].ke_type == KEYBUF_TYPE_GELI) {
- memcpy(key, keybuf->kb_ents[i].ke_data,
- sizeof(key));
-
- if (g_eli_mkey_decrypt_any(, key,
- mkey, ) == 0 ) {
- explicit_bzero(key, sizeof(key));
- goto have_key;
- }
- }
-}
-}
-
-for (i = 0; i <= tries; i++) {
-g_eli_crypto_hmac_init(, NULL, 0);
-
-/*
- * Load all key files.
- */
-nkeyfiles = g_eli_keyfiles_load(, pp->name);
-
-if (nkeyfiles == 0 && md.md_iterations == -1) {
-/*
- * No key files and no passphrase, something is
- * definitely wrong here.
- * geli(8) doesn't allow for such situation, 

git: 4b3141f5d537 - main - geli: allocate a UMA pool earlier

2024-05-19 Thread Mariusz Zaborski
The branch main has been updated by oshogbo:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4b3141f5d5373989598f9447ab5a9f87e2d1c9fb

commit 4b3141f5d5373989598f9447ab5a9f87e2d1c9fb
Author: Mariusz Zaborski 
AuthorDate: 2024-05-19 12:53:17 +
Commit: Mariusz Zaborski 
CommitDate: 2024-05-19 12:53:17 +

geli: allocate a UMA pool earlier

The functions g_eli_init_uma and g_eli_fini_uma are used to trace
the number of devices in GELI. There is an issue where the g_eli_create
function may fail before g_eli_init_uma is called, however
g_eli_fini_uma is still executed in the fail path. This can
incorrectly decrease the device count to zero, potentially leading to
the UMA pool being freed. Accessing the device after the pool has been
freed causes a system panic.

This commit resolves the issue by ensuring devices count is increassed
eariler.

PR: 278828
Reported by:Andre Albsmeier 
Reviewed by:asomers
MFC after:  3 days
Differential Revision:  https://reviews.freebsd.org/D45225
---
 sys/geom/eli/g_eli.c|  4 +++-
 tests/sys/geom/class/eli/attach_test.sh | 29 +
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c
index 5d769d606d20..ddb148ebd5db 100644
--- a/sys/geom/eli/g_eli.c
+++ b/sys/geom/eli/g_eli.c
@@ -1046,10 +1046,12 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, 
struct g_provider *bpp,
bioq_init(>sc_queue);
mtx_init(>sc_queue_mtx, "geli:queue", NULL, MTX_DEF);
mtx_init(>sc_ekeys_lock, "geli:ekeys", NULL, MTX_DEF);
+   g_eli_init_uma();
 
pp = NULL;
cp = g_new_consumer(gp);
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
+
error = g_attach(cp, bpp);
if (error != 0) {
if (req != NULL) {
@@ -1092,7 +1094,6 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, 
struct g_provider *bpp,
if (threads == 0)
threads = mp_ncpus;
sc->sc_cpubind = (mp_ncpus > 1 && threads == mp_ncpus);
-   g_eli_init_uma();
for (i = 0; i < threads; i++) {
if (g_eli_cpu_is_disabled(i)) {
G_ELI_DEBUG(1, "%s: CPU %u disabled, skipping.",
@@ -1164,6 +1165,7 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, 
struct g_provider *bpp,
sc->sc_crypto == G_ELI_CRYPTO_SW_ACCEL ? "accelerated software" :
sc->sc_crypto == G_ELI_CRYPTO_SW ? "software" : "hardware");
return (gp);
+
 failed:
mtx_lock(>sc_queue_mtx);
sc->sc_flags |= G_ELI_FLAG_DESTROY;
diff --git a/tests/sys/geom/class/eli/attach_test.sh 
b/tests/sys/geom/class/eli/attach_test.sh
index eb59234f014b..b6b1848f2d37 100644
--- a/tests/sys/geom/class/eli/attach_test.sh
+++ b/tests/sys/geom/class/eli/attach_test.sh
@@ -39,6 +39,34 @@ attach_d_cleanup()
geli_test_cleanup
 }
 
+atf_test_case atach_multiple_fails cleanup
+attach_multiple_fails_head()
+{
+   atf_set "descr" "test multiple failed attach of geli provider"
+   atf_set "require.user" "root"
+}
+attach_multiple_fails_body()
+{
+   geli_test_setup
+
+   sectors=1000
+   attach_md md -t malloc -s `expr $sectors + 1`
+   atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
+
+   atf_check geli init -B none -P -K keyfile ${md}
+   atf_check geli attach -d -p -k keyfile ${md}
+
+   for i in $(jot 100); do
+   atf_check -s not-exit:0 -e ignore -- geli attach -d -p -k 
keyfile ${md}
+   done
+   atf_check -o ignore -- newfs ${md}.eli
+}
+attach_multiple_fails_cleanup()
+{
+   geli_test_cleanup
+}
+
+
 atf_test_case attach_r cleanup
 attach_r_head()
 {
@@ -125,5 +153,6 @@ atf_init_test_cases()
atf_add_test_case attach_d
atf_add_test_case attach_r
atf_add_test_case attach_multiple
+   atf_add_test_case attach_multiple_fails
atf_add_test_case nokey
 }