Re: git: 9bcc1b18c119 - main - /bin/rmdir: Exit with status 2 for invalid arguments
Wouldn’t EX_USAGE fit really well? https://man.freebsd.org/cgi/man.cgi?query=sysexits&manpath=FreeBSD+4.3-RELEASE Regards, Ronald Van: Warner Losh Datum: 11 mei 2024 21:16 Aan: src-committ...@freebsd.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-m...@freebsd.org Onderwerp: git: 9bcc1b18c119 - main - /bin/rmdir: Exit with status 2 for invalid arguments The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9bcc1b18c119148e4455e548c90b2bc9cef16d1b commit 9bcc1b18c119148e4455e548c90b2bc9cef16d1b Author: Henrich Hartzer AuthorDate: 2024-05-10 17:53:49 + Commit: Warner Losh CommitDate: 2024-05-11 19:13:28 + /bin/rmdir: Exit with status 2 for invalid arguments PR: 277677 Signed-off-by: Henrich Hartzer Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1161 --- bin/rmdir/rmdir.1 | 15 --- bin/rmdir/rmdir.c | 2 +- bin/rmdir/tests/rmdir_test.sh | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bin/rmdir/rmdir.1 b/bin/rmdir/rmdir.1 index 87ca1f1547f0..eb23c605050c 100644 --- a/bin/rmdir/rmdir.1 +++ b/bin/rmdir/rmdir.1 @@ -74,14 +74,14 @@ The .Nm utility exits with one of the following values: .Bl -tag -width indent -.It Li 0 -Each directory entry specified by a +.It Er 0 +Each .Ar directory -operand -referred to an empty directory and was removed -successfully. -.It Li >0 -An error occurred. +referred to an empty directory and was removed successfully. +.It Er 1 +An error occurred while attempting to remove one or more directories. +.It Er 2 +Invalid arguments. .El .Sh EXAMPLES Remove the directory @@ -97,6 +97,7 @@ stopping at the first non-empty directory (if any): .Dl $ rmdir -p cow/horse/monkey .Sh SEE ALSO .Xr rm 1 +.Xr rmdir 2 .Sh STANDARDS The .Nm diff --git a/bin/rmdir/rmdir.c b/bin/rmdir/rmdir.c index c5d3db831309..0a495018495c 100644 --- a/bin/rmdir/rmdir.c +++ b/bin/rmdir/rmdir.c @@ -112,5 +112,5 @@ usage(void) { (void)fprintf(stderr, "usage: rmdir [-pv] directory ..."); - exit(1); + exit(2); } diff --git a/bin/rmdir/tests/rmdir_test.sh b/bin/rmdir/tests/rmdir_test.sh index d443849258b6..ba80ac6204be 100644 --- a/bin/rmdir/tests/rmdir_test.sh +++ b/bin/rmdir/tests/rmdir_test.sh @@ -35,8 +35,8 @@ invalid_usage_head() invalid_usage_body() { - atf_check -s not-exit:0 -e match:"$usage_output" rmdir -p - atf_check -s not-exit:0 -e match:"$usage_output" rmdir -v + atf_check -s exit:2 -e match:"$usage_output" rmdir -p + atf_check -s exit:2 -e match:"$usage_output" rmdir -v } atf_test_case no_arguments @@ -47,7 +47,7 @@ no_arguments_head() no_arguments_body() { - atf_check -s not-exit:0 -e match:"$usage_output" rmdir + atf_check -s exit:2 -e match:"$usage_output" rmdir } atf_init_test_cases()
git: 78e4dbc34559 - main - ipfw: Fix a typo in a source code comment
The branch main has been updated by gbe: URL: https://cgit.FreeBSD.org/src/commit/?id=78e4dbc34559f7b18ea85cafd6663db4e6d54af9 commit 78e4dbc34559f7b18ea85cafd6663db4e6d54af9 Author: Gordon Bergling AuthorDate: 2024-05-12 08:53:40 + Commit: Gordon Bergling CommitDate: 2024-05-12 08:53:40 + ipfw: Fix a typo in a source code comment - s/defaul/default/ MFC after: 3 days --- sys/netinet/ip_fw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/netinet/ip_fw.h b/sys/netinet/ip_fw.h index 2b59e46b5bcc..937dc8fbbbc2 100644 --- a/sys/netinet/ip_fw.h +++ b/sys/netinet/ip_fw.h @@ -979,7 +979,7 @@ typedef struct _ipfw_range_tlv { #defineIPFW_RCFLAG_USER(IPFW_RCFLAG_RANGE | IPFW_RCFLAG_ALL | \ IPFW_RCFLAG_SET | IPFW_RCFLAG_DYNAMIC) /* Internally used flags */ -#defineIPFW_RCFLAG_DEFAULT 0x0100 /* Do not skip defaul rule */ +#defineIPFW_RCFLAG_DEFAULT 0x0100 /* Do not skip default rule */ typedef struct _ipfw_ta_tinfo { uint32_tflags; /* Format flags */
Re: git: 9bcc1b18c119 - main - /bin/rmdir: Exit with status 2 for invalid arguments
On Sun, May 12, 2024, 1:30 AM Ronald Klop wrote: > Wouldn’t EX_USAGE fit really well? > > > https://man.freebsd.org/cgi/man.cgi?query=sysexits&manpath=FreeBSD+4.3-RELEASE > Read the pull request. Warner > Regards, > Ronald > > *Van:* Warner Losh > *Datum:* 11 mei 2024 21:16 > *Aan:* src-committ...@freebsd.org, dev-commits-src-all@FreeBSD.org, > dev-commits-src-m...@freebsd.org > *Onderwerp:* git: 9bcc1b18c119 - main - /bin/rmdir: Exit with status 2 > for invalid arguments > > The branch main has been updated by imp: > > URL: > https://cgit.FreeBSD.org/src/commit/?id=9bcc1b18c119148e4455e548c90b2bc9cef16d1b > > commit 9bcc1b18c119148e4455e548c90b2bc9cef16d1b > Author: Henrich Hartzer > AuthorDate: 2024-05-10 17:53:49 + > Commit: Warner Losh > CommitDate: 2024-05-11 19:13:28 + > > /bin/rmdir: Exit with status 2 for invalid arguments > > PR: 277677 > > Signed-off-by: Henrich Hartzer > Reviewed by: imp > Pull Request: https://github.com/freebsd/freebsd-src/pull/1161 > --- > bin/rmdir/rmdir.1 | 15 --- > bin/rmdir/rmdir.c | 2 +- > bin/rmdir/tests/rmdir_test.sh | 6 +++--- > 3 files changed, 12 insertions(+), 11 deletions(-) > > diff --git a/bin/rmdir/rmdir.1 b/bin/rmdir/rmdir.1 > index 87ca1f1547f0..eb23c605050c 100644 > --- a/bin/rmdir/rmdir.1 > +++ b/bin/rmdir/rmdir.1 > @@ -74,14 +74,14 @@ The > .Nm > utility exits with one of the following values: > .Bl -tag -width indent > -.It Li 0 > -Each directory entry specified by a > +.It Er 0 > +Each > .Ar directory > -operand > -referred to an empty directory and was removed > -successfully. > -.It Li >0 > -An error occurred. > +referred to an empty directory and was removed successfully. > +.It Er 1 > +An error occurred while attempting to remove one or more directories. > +.It Er 2 > +Invalid arguments. > .El > .Sh EXAMPLES > Remove the directory > @@ -97,6 +97,7 @@ stopping at the first non-empty directory (if any): > .Dl $ rmdir -p cow/horse/monkey > .Sh SEE ALSO > .Xr rm 1 > +.Xr rmdir 2 > .Sh STANDARDS > The > .Nm > diff --git a/bin/rmdir/rmdir.c b/bin/rmdir/rmdir.c > index c5d3db831309..0a495018495c 100644 > --- a/bin/rmdir/rmdir.c > +++ b/bin/rmdir/rmdir.c > @@ -112,5 +112,5 @@ usage(void) > { > > (void)fprintf(stderr, "usage: rmdir [-pv] directory ... "); > - exit(1); > + exit(2); > } > diff --git a/bin/rmdir/tests/rmdir_test.sh b/bin/rmdir/tests/rmdir_test.sh > index d443849258b6..ba80ac6204be 100644 > --- a/bin/rmdir/tests/rmdir_test.sh > +++ b/bin/rmdir/tests/rmdir_test.sh > @@ -35,8 +35,8 @@ invalid_usage_head() > > invalid_usage_body() > { > - atf_check -s not-exit:0 -e match:"$usage_output" rmdir -p > - atf_check -s not-exit:0 -e match:"$usage_output" rmdir -v > + atf_check -s exit:2 -e match:"$usage_output" rmdir -p > + atf_check -s exit:2 -e match:"$usage_output" rmdir -v > } > > atf_test_case no_arguments > @@ -47,7 +47,7 @@ no_arguments_head() > > no_arguments_body() > { > - atf_check -s not-exit:0 -e match:"$usage_output" rmdir > + atf_check -s exit:2 -e match:"$usage_output" rmdir > } > > atf_init_test_cases() > > -- > > > > >
Re: git: 099a81a4173b - main - linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
On Sat, May 11, 2024 at 07:39:18PM +, Warner Losh wrote: > The branch main has been updated by imp: > > URL: > https://cgit.FreeBSD.org/src/commit/?id=099a81a4173bc5b121e50d4e27ea5fafdda8475b > > commit 099a81a4173bc5b121e50d4e27ea5fafdda8475b > Author: Ricardo Branco > AuthorDate: 2024-05-04 13:38:20 + > Commit: Warner Losh > CommitDate: 2024-05-11 19:37:47 + > > linprocfs: Add support for proc/sysvipc/{msg,sem,shm} > > Signed-off-by: Ricardo Branco > Reviewed by: imp > Pull Request: https://github.com/freebsd/freebsd-src/pull/1218 > --- > sys/compat/linprocfs/linprocfs.c | 182 > +++ > 1 file changed, 182 insertions(+) > > diff --git a/sys/compat/linprocfs/linprocfs.c > b/sys/compat/linprocfs/linprocfs.c > index 391d5f679ee5..a877d4065c18 100644 > --- a/sys/compat/linprocfs/linprocfs.c > +++ b/sys/compat/linprocfs/linprocfs.c > @@ -126,6 +126,9 @@ > #define P2K(x) ((x) << (PAGE_SHIFT - 10))/* pages to kbytes */ > #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 1) > > +/* Value defined in sys/kern/sysv_shm.c */ > +#define SHMSEG_ALLOCATED 0x0800 > + > /** > * @brief Mapping of ki_stat in struct kinfo_proc to the linux state > * > @@ -2092,6 +2095,176 @@ linprocfs_domax_map_cnt(PFS_FILL_ARGS) > return (0); > } > > +/* > + * Filler function for proc/sysvipc/msg > + */ > +static int > +linprocfs_dosysvipc_msg(PFS_FILL_ARGS) > +{ > + struct msqid_kernel *msqids; > + u_long id, msgmni; > + size_t sz; > + int error; > + > + sbuf_printf(sb, > + "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n", > + "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", > + "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); > + > +again: > + msgmni = msginfo.msgmni; > + sz = sizeof(struct msqid_kernel) * msgmni; > + msqids = malloc(sz, M_TEMP, M_NOWAIT); Why M_NOWAIT? What does prevent us from waiting there? > + if (msqids == NULL) > + return (ENOMEM); > + if (msgmni != msginfo.msgmni) { What prevents msginfo.msgmni from changing again? Otherwise, why this check is needed? (Same questions for other two similar places trimmed below).
Re: git: ee2e36686e84 - main - linprocfs: Really fix time_t type issue
On Sun, May 12, 2024 at 04:57:19AM +, Warner Losh wrote: > The branch main has been updated by imp: > > URL: > https://cgit.FreeBSD.org/src/commit/?id=ee2e36686e846d412deac23344185f4b8a8c0285 > > commit ee2e36686e846d412deac23344185f4b8a8c0285 > Author: Warner Losh > AuthorDate: 2024-05-12 04:53:15 + > Commit: Warner Losh > CommitDate: 2024-05-12 04:53:15 + > > linprocfs: Really fix time_t type issue > > The cast to (long) is wrong on all the other 32-bit platforms. (long > long) is the correct type on all platforms. Also, use a z modifier for > size_t which also fails on 32-bit platforms. > > Fixes: 02f481a30b82 > Sponsored by: Netflix > --- > sys/compat/linprocfs/linprocfs.c | 22 +++--- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/sys/compat/linprocfs/linprocfs.c > b/sys/compat/linprocfs/linprocfs.c > index aa5af0b3c1c1..dd04adc054db 100644 > --- a/sys/compat/linprocfs/linprocfs.c > +++ b/sys/compat/linprocfs/linprocfs.c > @@ -2133,7 +2133,7 @@ again: > for (id = 0; id < msgmni; id++) > if (msqids[id].u.msg_qbytes != 0) > sbuf_printf(sb, > - "%10d %10lu %4o %10lu %10lu %5u %5u %5u %5u %5u > %5u %10ld %10ld %10ld\n", > + "%10d %10lu %4o %10lu %10lu %5u %5u %5u %5u %5u > %5u %10lld %10lld %10lld\n", > (int) msqids[id].u.msg_perm.key, > IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm), > msqids[id].u.msg_perm.mode, The canonical and bde' approved way to print integrals which size if MD is to use %jd format modifier and cast to intmax_t.
git: 71ffda413069 - main - Revert linprocfs commits
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=71ffda413069ca39eabebbe83151df02d01c9103 commit 71ffda413069ca39eabebbe83151df02d01c9103 Author: Warner Losh AuthorDate: 2024-05-12 15:08:39 + Commit: Warner Losh CommitDate: 2024-05-12 15:09:03 + Revert linprocfs commits There's a race in these that I missed in my review that needs to be resolved. This reverts commit ee2e36686e846d412deac23344185f4b8a8c0285. This reverts commit 02f481a30b8269c7cad24ec2920ca09751708a1e. This reverts commit 099a81a4173bc5b121e50d4e27ea5fafdda8475b. --- sys/compat/linprocfs/linprocfs.c | 182 --- 1 file changed, 182 deletions(-) diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index dd04adc054db..391d5f679ee5 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -126,9 +126,6 @@ #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ #define TV2J(x)((x)->tv_sec * 100UL + (x)->tv_usec / 1) -/* Value defined in sys/kern/sysv_shm.c */ -#define SHMSEG_ALLOCATED 0x0800 - /** * @brief Mapping of ki_stat in struct kinfo_proc to the linux state * @@ -2095,176 +2092,6 @@ linprocfs_domax_map_cnt(PFS_FILL_ARGS) return (0); } -/* - * Filler function for proc/sysvipc/msg - */ -static int -linprocfs_dosysvipc_msg(PFS_FILL_ARGS) -{ - struct msqid_kernel *msqids; - u_long id, msgmni; - size_t sz; - int error; - - sbuf_printf(sb, - "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n", - "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", - "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); - -again: - msgmni = msginfo.msgmni; - sz = sizeof(struct msqid_kernel) * msgmni; - msqids = malloc(sz, M_TEMP, M_NOWAIT); - if (msqids == NULL) - return (ENOMEM); - if (msgmni != msginfo.msgmni) { - free(msqids, M_TEMP); - goto again; - } - - error = kernel_sysctlbyname(curthread, "kern.ipc.msqids", msqids, &sz, - NULL, 0, 0, 0); - if (error != 0) { - free(msqids, M_TEMP); - return (error); - } - msgmni = sz / sizeof(struct msqid_kernel); - - for (id = 0; id < msgmni; id++) - if (msqids[id].u.msg_qbytes != 0) - sbuf_printf(sb, - "%10d %10lu %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lld %10lld %10lld\n", - (int) msqids[id].u.msg_perm.key, - IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm), - msqids[id].u.msg_perm.mode, - msqids[id].u.msg_cbytes, - msqids[id].u.msg_qnum, - msqids[id].u.msg_lspid, - msqids[id].u.msg_lrpid, - msqids[id].u.msg_perm.uid, - msqids[id].u.msg_perm.gid, - msqids[id].u.msg_perm.cuid, - msqids[id].u.msg_perm.cgid, - (long long)msqids[id].u.msg_stime, - (long long)msqids[id].u.msg_rtime, - (long long)msqids[id].u.msg_ctime); - - free(msqids, M_TEMP); - return (0); -} - -/* - * Filler function for proc/sysvipc/sem - */ -static int -linprocfs_dosysvipc_sem(PFS_FILL_ARGS) -{ - struct semid_kernel *semids; - u_long id, semmni; - size_t sz; - int error; - - sbuf_printf(sb, "%10s %10s %4s %10s %5s %5s %5s %5s %10s %10s\n", - "key", "semid", "perms", "nsems", "uid", "gid", "cuid", "cgid", - "otime", "ctime"); - -again: - semmni = seminfo.semmni; - sz = sizeof(struct semid_kernel) * semmni; - semids = malloc(sz, M_TEMP, M_NOWAIT); - if (semids == NULL) - return (ENOMEM); - if (semmni != seminfo.semmni) { - free(semids, M_TEMP); - goto again; - } - - error = kernel_sysctlbyname(curthread, "kern.ipc.sema", semids, &sz, - NULL, 0, 0, 0); - if (error != 0) { - free(semids, M_TEMP); - return (error); - } - semmni = sz / sizeof(struct semid_kernel); - - for (id = 0; id < semmni; id++) - if ((semids[id].u.sem_perm.mode & SEM_ALLOC) != 0) - sbuf_printf(sb, - "%10d %10lu %4o %10u %5u %5u %5u %5u %10lld %10lld\n", - (int) semids[id].u.sem_perm.key, - IXSEQ_TO_IPCID(id, semids[id].u.sem_perm), - semids[id].u.sem_perm.mode, - semids[id].u.sem_nsems, - semids[id].u
Re: git: 099a81a4173b - main - linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
On Sun, May 12, 2024 at 5:36 AM Konstantin Belousov wrote: > On Sat, May 11, 2024 at 07:39:18PM +, Warner Losh wrote: > > The branch main has been updated by imp: > > > > URL: > https://cgit.FreeBSD.org/src/commit/?id=099a81a4173bc5b121e50d4e27ea5fafdda8475b > > > > commit 099a81a4173bc5b121e50d4e27ea5fafdda8475b > > Author: Ricardo Branco > > AuthorDate: 2024-05-04 13:38:20 + > > Commit: Warner Losh > > CommitDate: 2024-05-11 19:37:47 + > > > > linprocfs: Add support for proc/sysvipc/{msg,sem,shm} > > > > Signed-off-by: Ricardo Branco > > Reviewed by: imp > > Pull Request: https://github.com/freebsd/freebsd-src/pull/1218 > > --- > > sys/compat/linprocfs/linprocfs.c | 182 > +++ > > 1 file changed, 182 insertions(+) > > > > diff --git a/sys/compat/linprocfs/linprocfs.c > b/sys/compat/linprocfs/linprocfs.c > > index 391d5f679ee5..a877d4065c18 100644 > > --- a/sys/compat/linprocfs/linprocfs.c > > +++ b/sys/compat/linprocfs/linprocfs.c > > @@ -126,6 +126,9 @@ > > #define P2K(x) ((x) << (PAGE_SHIFT - 10))/* pages to kbytes > */ > > #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 1) > > > > +/* Value defined in sys/kern/sysv_shm.c */ > > +#define SHMSEG_ALLOCATED 0x0800 > > + > > /** > > * @brief Mapping of ki_stat in struct kinfo_proc to the linux state > > * > > @@ -2092,6 +2095,176 @@ linprocfs_domax_map_cnt(PFS_FILL_ARGS) > > return (0); > > } > > > > +/* > > + * Filler function for proc/sysvipc/msg > > + */ > > +static int > > +linprocfs_dosysvipc_msg(PFS_FILL_ARGS) > > +{ > > + struct msqid_kernel *msqids; > > + u_long id, msgmni; > > + size_t sz; > > + int error; > > + > > + sbuf_printf(sb, > > + "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s > %10s\n", > > + "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", > > + "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); > > + > > +again: > > + msgmni = msginfo.msgmni; > > + sz = sizeof(struct msqid_kernel) * msgmni; > > + msqids = malloc(sz, M_TEMP, M_NOWAIT); > Why M_NOWAIT? What does prevent us from waiting there? > Oh, I missed that in my review. It should just be wait. You are right. > > + if (msqids == NULL) > > + return (ENOMEM); > > + if (msgmni != msginfo.msgmni) { > What prevents msginfo.msgmni from changing again? Otherwise, why this > check > is needed? > > (Same questions for other two similar places trimmed below). > I found other races that I commented on, but missed these somehow. I'd also bucketed the PR as simple, not in need of closer review by others, which I'll bias towards wider review more in the future. I've backed this out, as well as my "fixes" to it. You are of course correct on the uintmax_t thing... I'd internalized that rule only for [u]intXX_t, but of course it applies across the board. I don't know what I was thinking. I'll work with the submitter to tighten these things up, providing additional interfaces if necessary. Should I add you to the reviews once the preliminaries and mechanical issues are dealt with? Warner
Re: git: 099a81a4173b - main - linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
On Sun, May 12, 2024 at 09:28:29AM -0600, Warner Losh wrote: > On Sun, May 12, 2024 at 5:36 AM Konstantin Belousov > wrote: > > > On Sat, May 11, 2024 at 07:39:18PM +, Warner Losh wrote: > > > The branch main has been updated by imp: > > > > > > URL: > > https://cgit.FreeBSD.org/src/commit/?id=099a81a4173bc5b121e50d4e27ea5fafdda8475b > > > > > > commit 099a81a4173bc5b121e50d4e27ea5fafdda8475b > > > Author: Ricardo Branco > > > AuthorDate: 2024-05-04 13:38:20 + > > > Commit: Warner Losh > > > CommitDate: 2024-05-11 19:37:47 + > > > > > > linprocfs: Add support for proc/sysvipc/{msg,sem,shm} > > > > > > Signed-off-by: Ricardo Branco > > > Reviewed by: imp > > > Pull Request: https://github.com/freebsd/freebsd-src/pull/1218 > > > --- > > > sys/compat/linprocfs/linprocfs.c | 182 > > +++ > > > 1 file changed, 182 insertions(+) > > > > > > diff --git a/sys/compat/linprocfs/linprocfs.c > > b/sys/compat/linprocfs/linprocfs.c > > > index 391d5f679ee5..a877d4065c18 100644 > > > --- a/sys/compat/linprocfs/linprocfs.c > > > +++ b/sys/compat/linprocfs/linprocfs.c > > > @@ -126,6 +126,9 @@ > > > #define P2K(x) ((x) << (PAGE_SHIFT - 10))/* pages to kbytes > > */ > > > #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 1) > > > > > > +/* Value defined in sys/kern/sysv_shm.c */ > > > +#define SHMSEG_ALLOCATED 0x0800 > > > + > > > /** > > > * @brief Mapping of ki_stat in struct kinfo_proc to the linux state > > > * > > > @@ -2092,6 +2095,176 @@ linprocfs_domax_map_cnt(PFS_FILL_ARGS) > > > return (0); > > > } > > > > > > +/* > > > + * Filler function for proc/sysvipc/msg > > > + */ > > > +static int > > > +linprocfs_dosysvipc_msg(PFS_FILL_ARGS) > > > +{ > > > + struct msqid_kernel *msqids; > > > + u_long id, msgmni; > > > + size_t sz; > > > + int error; > > > + > > > + sbuf_printf(sb, > > > + "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s > > %10s\n", > > > + "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", > > > + "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); > > > + > > > +again: > > > + msgmni = msginfo.msgmni; > > > + sz = sizeof(struct msqid_kernel) * msgmni; > > > + msqids = malloc(sz, M_TEMP, M_NOWAIT); > > Why M_NOWAIT? What does prevent us from waiting there? > > > > Oh, I missed that in my review. It should just be wait. You are right. > > > > > + if (msqids == NULL) > > > + return (ENOMEM); > > > + if (msgmni != msginfo.msgmni) { > > What prevents msginfo.msgmni from changing again? Otherwise, why this > > check > > is needed? > > > > (Same questions for other two similar places trimmed below). > > > > I found other races that I commented on, but missed these somehow. I'd also > bucketed the PR as simple, not in need of closer review by others, which > I'll bias towards wider review more in the future. > > I've backed this out, as well as my "fixes" to it. You are of course > correct on the uintmax_t thing... I'd internalized that rule only for > [u]intXX_t, but of course it applies across the board. I don't know what I > was thinking. I'll work with the submitter to tighten these things up, > providing additional interfaces if necessary. Should I add you to the > reviews once the preliminaries and mechanical issues are dealt with? FWIW, I am not sure that the issues are worth the revert. The time_t format is definitely a mechanical/small problem. Same for the M_NOWAIT/WAITOK. The recheck is more problematic, I do agree. Also, I realized one more issue there: the data structures like msginfo are from sysvmsg.ko modules. Then, the change make linprocfs depending on the sysv*.ko, but this is not directly recorded with MODULE_DEPENDS(). It worked because GENERIC compiles SysV support statically.
git: fe13793bb442 - releng/14.1 - linuxkpi: Make arch_io_*_memtype_wc amd64-only
The branch releng/14.1 has been updated by tijl: URL: https://cgit.FreeBSD.org/src/commit/?id=fe13793bb44212607c231a9c793de05aea74dc7b commit fe13793bb44212607c231a9c793de05aea74dc7b Author: Tijl Coosemans AuthorDate: 2024-05-08 18:49:56 + Commit: Tijl Coosemans CommitDate: 2024-05-12 15:56:55 + linuxkpi: Make arch_io_*_memtype_wc amd64-only Linux only implements these functions on x86. They return 0 on other architectures. The FreeBSD implementation calls PHYS_TO_DMAP but this panics on i386 because it does not have a direct map so return 0 on i386 as well for now. These functions are only used by graphics/drm-*-kmod to mark the VRAM aperture write-combining but this is also accomplished by a call to vm_phys_fictitious_reg_range so this change is sufficient to fix drm-*-kmod on i386 for FreeBSD 14.1. Reviewed by:kib Approved by:re (cperciva) Differential Revision: https://reviews.freebsd.org/D45125 (cherry picked from commit 2ae0f5a4d0931067c672be9a791909f0e32d5a0e) (cherry picked from commit 2d97bd0639cd0af43b7beb6f45ef15bcf110db57) --- sys/compat/linuxkpi/common/include/linux/io.h | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/io.h b/sys/compat/linuxkpi/common/include/linux/io.h index bce70ed0cb8d..164347dbc4e7 100644 --- a/sys/compat/linuxkpi/common/include/linux/io.h +++ b/sys/compat/linuxkpi/common/include/linux/io.h @@ -541,30 +541,29 @@ void lkpi_arch_phys_wc_del(int); #definearch_phys_wc_index(x) \ (((x) < __MTRR_ID_BASE) ? -1 : ((x) - __MTRR_ID_BASE)) -#if defined(__amd64__) || defined(__i386__) || defined(__aarch64__) || defined(__powerpc__) || defined(__riscv) static inline int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size) { +#if defined(__amd64__) vm_offset_t va; va = PHYS_TO_DMAP(start); - -#ifdef VM_MEMATTR_WRITE_COMBINING return (-pmap_change_attr(va, size, VM_MEMATTR_WRITE_COMBINING)); #else - return (-pmap_change_attr(va, size, VM_MEMATTR_UNCACHEABLE)); + return (0); #endif } static inline void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size) { +#if defined(__amd64__) vm_offset_t va; va = PHYS_TO_DMAP(start); pmap_change_attr(va, size, VM_MEMATTR_WRITE_BACK); -} #endif +} #endif /* _LINUXKPI_LINUX_IO_H_ */
git: e6cdeb9d9187 - releng/14.1 - linuxkpi: Fix set_memory_*
The branch releng/14.1 has been updated by tijl: URL: https://cgit.FreeBSD.org/src/commit/?id=e6cdeb9d91875773a64ef61b5a9dcfb0ded90799 commit e6cdeb9d91875773a64ef61b5a9dcfb0ded90799 Author: Tijl Coosemans AuthorDate: 2024-05-03 13:27:29 + Commit: Tijl Coosemans CommitDate: 2024-05-12 15:55:14 + linuxkpi: Fix set_memory_* set_memory_* is currently implemented using PHYS_TO_DMAP but not all architectures have a DMAP. Looking at how this function is used the given address isn't physical but virtual so the PHYS_TO_DMAP call can simply be removed. Also cast numpages before shifting it to avoid overflow. Reviewed by:kib, markj Approved by:re (cperciva) Differential Revision: https://reviews.freebsd.org/D45057 (cherry picked from commit 7206f7c619912bdd4d54dd539824733eae50c3a9) (cherry picked from commit 147ea7d4092f4b08411724bd501283a281ffa34e) --- sys/compat/linuxkpi/common/include/asm/set_memory.h | 21 ++--- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/asm/set_memory.h b/sys/compat/linuxkpi/common/include/asm/set_memory.h index 69f659001c60..1019aaf264a0 100644 --- a/sys/compat/linuxkpi/common/include/asm/set_memory.h +++ b/sys/compat/linuxkpi/common/include/asm/set_memory.h @@ -34,26 +34,20 @@ static inline int set_memory_uc(unsigned long addr, int numpages) { - vm_offset_t va; vm_size_t len; - va = PHYS_TO_DMAP(addr); - len = numpages << PAGE_SHIFT; - - return (-pmap_change_attr(va, len, VM_MEMATTR_UNCACHEABLE)); + len = (vm_size_t)numpages << PAGE_SHIFT; + return (-pmap_change_attr(addr, len, VM_MEMATTR_UNCACHEABLE)); } static inline int set_memory_wc(unsigned long addr, int numpages) { #ifdef VM_MEMATTR_WRITE_COMBINING - vm_offset_t va; vm_size_t len; - va = PHYS_TO_DMAP(addr); - len = numpages << PAGE_SHIFT; - - return (-pmap_change_attr(va, len, VM_MEMATTR_WRITE_COMBINING)); + len = (vm_size_t)numpages << PAGE_SHIFT; + return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_COMBINING)); #else return (set_memory_uc(addr, numpages)); #endif @@ -62,13 +56,10 @@ set_memory_wc(unsigned long addr, int numpages) static inline int set_memory_wb(unsigned long addr, int numpages) { - vm_offset_t va; vm_size_t len; - va = PHYS_TO_DMAP(addr); - len = numpages << PAGE_SHIFT; - - return (-pmap_change_attr(va, len, VM_MEMATTR_WRITE_BACK)); + len = (vm_size_t)numpages << PAGE_SHIFT; + return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_BACK)); } static inline int
git: 9a8a26aefb36 - stable/14 - if: guard against if_ioctl being NULL
The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=9a8a26aefb366ef6f497d48547a1562a1de566c1 commit 9a8a26aefb366ef6f497d48547a1562a1de566c1 Author: Kristof Provost AuthorDate: 2024-05-06 09:39:08 + Commit: Kristof Provost CommitDate: 2024-05-12 16:12:04 + if: guard against if_ioctl being NULL There are situations where an struct ifnet has a NULL if_ioctl pointer. For example, e6000sw creates such struct ifnets for each of its ports so it can call into the MII code. If there is then a link state event this calls do_link_state_change() -> rtnl_handle_ifevent() -> dump_iface() -> get_operstate() -> get_operstate_ether(). That wants to know if the link is up or down, so it tries to ioctl(SIOCGIFMEDIA), which doesn't go well if if_ioctl is NULL. Guard against this, and return EOPNOTSUPP. PR: 275920 MFC ater: 3 days Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 43387b4e574043b78a58c8bcb7575161b055fce1) --- sys/net/if.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index 0128fb8039ee..1ca0893eb724 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -4873,6 +4873,9 @@ if_resolvemulti(if_t ifp, struct sockaddr **srcs, struct sockaddr *dst) int if_ioctl(if_t ifp, u_long cmd, void *data) { + if (ifp->if_ioctl == NULL) + return (EOPNOTSUPP); + return (ifp->if_ioctl(ifp, cmd, data)); }
git: 502a1018002e - releng/14.1 - bhyve: Do not define GDB_LOG
The branch releng/14.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=502a1018002e418df05c801edd03572129feb36c commit 502a1018002e418df05c801edd03572129feb36c Author: Mark Johnston AuthorDate: 2024-05-08 16:06:22 + Commit: Mark Johnston CommitDate: 2024-05-12 16:36:26 + bhyve: Do not define GDB_LOG This had been added for debugging and shouldn't have been committed. Approved by:re (cperciva) Fixes: f81cdf24ba54 ("bhyve: Add support for XML register definitions") MFC after: 3 days (cherry picked from commit 5d62025d82a0be928f98778d54b25ad89edbb835) (cherry picked from commit d8ccaa995f4539081f79e9b31ff0ac75173e1004) --- usr.sbin/bhyve/gdb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 2a075cd10ca6..0319aaf0a9cd 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -193,7 +193,6 @@ static const struct gdb_reg { { .id = VM_REG_GUEST_EFER, .size = 8 }, }; -#defineGDB_LOG #ifdef GDB_LOG #include #include
git: 47535ba3d35e - main - bsdinstall: Remove unused variables in fetchmissingdists
The branch main has been updated by fernape: URL: https://cgit.FreeBSD.org/src/commit/?id=47535ba3d35eda44d1eb961551173a9dadef17fa commit 47535ba3d35eda44d1eb961551173a9dadef17fa Author: Fernando Apesteguía AuthorDate: 2023-10-26 12:16:54 + Commit: Fernando Apesteguía CommitDate: 2024-05-12 17:25:06 + bsdinstall: Remove unused variables in fetchmissingdists ALL_DISTRIBUTIONS and VERIFY_MANIFEST_SIG They are neither used in the script nor exported. Not referenced anywhere in bsdinstall/* Approved by:imp@ Differential Revision: https://reviews.freebsd.org/D42369 --- usr.sbin/bsdinstall/scripts/fetchmissingdists | 3 --- 1 file changed, 3 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/fetchmissingdists b/usr.sbin/bsdinstall/scripts/fetchmissingdists index d37acc96b92c..f5da3ee45c39 100644 --- a/usr.sbin/bsdinstall/scripts/fetchmissingdists +++ b/usr.sbin/bsdinstall/scripts/fetchmissingdists @@ -53,7 +53,6 @@ if [ -z "$FETCH_DISTRIBUTIONS" ]; then exit 0 fi -ALL_DISTRIBUTIONS="$DISTRIBUTIONS" WANT_DEBUG= # Download to a directory in the new system as scratch space @@ -75,10 +74,8 @@ export FTP_PASSIVE_MODE=YES if [ -f "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" ]; then cp "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" "$BSDINSTALL_DISTDIR/MANIFEST" - VERIFY_MANIFEST_SIG=0 else FETCH_DISTRIBUTIONS="MANIFEST $FETCH_DISTRIBUTIONS" - VERIFY_MANIFEST_SIG=1 # XXX actually verify signature on manifest bsddialog --backtitle "$OSNAME Installer" --title "Warning" --msgbox "Manifest not found on local disk and will be fetched from an unverified source. This is a potential security risk. If you do not wish to proceed, press control-C now." 0 0
git: aec52a27f987 - releng/14.1 - Merge commit 5300a6731e98 from llvm-project (by Jonathan Peyton):
The branch releng/14.1 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=aec52a27f987eef4f21c07f83cdc783fbdede2db commit aec52a27f987eef4f21c07f83cdc783fbdede2db Author: Dimitry Andric AuthorDate: 2024-05-08 16:55:08 + Commit: Dimitry Andric CommitDate: 2024-05-12 18:08:18 + Merge commit 5300a6731e98 from llvm-project (by Jonathan Peyton): [OpenMP] Fix re-locking hang found in issue 86684 (#88539) This was initially reported here (including stacktraces): https://stackoverflow.com/questions/78183545/does-compiling-imagick-with-openmp-enabled-in-freebsd-13-2-cause-sched-yield If `__kmp_register_library_startup()` detects that another instance of the library is present, `__kmp_is_address_mapped()` is eventually called. which uses `kmpc_alloc()` to allocate memory. This function calls `__kmp_entry_thread()` to access the thread-local memory pool, which is a bad idea during initialization. This macro internally calls `__kmp_get_global_thread_id_reg()` which sets the bootstrap lock at the beginning (before calling `__kmp_register_library_startup()`). The fix is to use `KMP_INTERNAL_MALLOC()`/`KMP_INTERNAL_FREE()` instead of `kmpc_malloc()`/`kmpc_free()`. `KMP_INTERNAL_MALLOC` and `KMP_INTERNAL_FREE` do not use any bootstrap locks. They just translate to `malloc()`/`free()` and are meant to be used during library initialization before other library-specific allocators have been initialized. Fixes: #86684 This should fix OpenMP processes sometimes getting locked with 100% CPU usage, endlessly calling sched_yield(2). PR: 278845 Reported by:Cassidy B. Larson Approved by:re (cperciva) MFC after: 3 days (cherry picked from commit da15ed2e982180198f77a0fa26628e6d414cb10e) (cherry picked from commit 426e07d791641e80e90af89d52008635a35e4794) --- contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp b/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp index b9ff96873702..97ddb8a608b7 100644 --- a/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp +++ b/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp @@ -2129,10 +2129,10 @@ int __kmp_is_address_mapped(void *addr) { // We pass from number of vm entry's semantic // to size of whole entry map list. lstsz = lstsz * 4 / 3; - buf = reinterpret_cast(kmpc_malloc(lstsz)); + buf = reinterpret_cast(KMP_INTERNAL_MALLOC(lstsz)); rc = sysctl(mib, 4, buf, &lstsz, NULL, 0); if (rc < 0) { -kmpc_free(buf); +KMP_INTERNAL_FREE(buf); return 0; } @@ -2156,7 +2156,7 @@ int __kmp_is_address_mapped(void *addr) { } lw += cursz; } - kmpc_free(buf); + KMP_INTERNAL_FREE(buf); #elif KMP_OS_DARWIN
git: ba0bd7cea412 - releng/14.1 - Merge commit 73bb8d9d92f6 from llvm-project (by Jonathan Peyton):
The branch releng/14.1 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=ba0bd7cea412c6dc51ebfebd4000a543e49013bd commit ba0bd7cea412c6dc51ebfebd4000a543e49013bd Author: Dimitry Andric AuthorDate: 2024-05-08 18:44:28 + Commit: Dimitry Andric CommitDate: 2024-05-12 18:08:46 + Merge commit 73bb8d9d92f6 from llvm-project (by Jonathan Peyton): [OpenMP] Fix child processes to use affinity_none (#91391) When a child process is forked with OpenMP already initialized, the child process resets its affinity mask and sets proc-bind-var to false so that the entire original affinity mask is used. This patch corrects an issue with the affinity initialization code setting affinity to compact instead of none for this special case of forked children. The test trying to catch this only testing explicit setting of KMP_AFFINITY=none. Add test run for no KMP_AFFINITY setting. Fixes: #91098 This should fix OpenMP processes sometimes getting stuck on a single CPU core. PR: 278845 Reported by:Cassidy B. Larson Approved by:re (cperciva) MFC after: 3 days (cherry picked from commit 22b3e7898ecdf90887a9536fab5b9a6f7a291723) (cherry picked from commit 91df7d335dd44fa3cf506b35987d791502613ed4) --- contrib/llvm-project/openmp/runtime/src/kmp_settings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/llvm-project/openmp/runtime/src/kmp_settings.cpp b/contrib/llvm-project/openmp/runtime/src/kmp_settings.cpp index ec86ee07472c..58f19ea5b8ab 100644 --- a/contrib/llvm-project/openmp/runtime/src/kmp_settings.cpp +++ b/contrib/llvm-project/openmp/runtime/src/kmp_settings.cpp @@ -6426,6 +6426,8 @@ void __kmp_env_initialize(char const *string) { } if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) && (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) { + if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false) +__kmp_affinity.type = affinity_none; if (__kmp_affinity.type == affinity_default) { __kmp_affinity.type = affinity_compact; __kmp_affinity.flags.dups = FALSE;
git: 94b09d388b81 - main - arm64: map kernel using large pages when page size is 16K
The branch main has been updated by alc: URL: https://cgit.FreeBSD.org/src/commit/?id=94b09d388b81eb724769e506cdf0f51bba9b73fb commit 94b09d388b81eb724769e506cdf0f51bba9b73fb Author: Alan Cox AuthorDate: 2024-05-11 06:09:39 + Commit: Alan Cox CommitDate: 2024-05-12 23:22:38 + arm64: map kernel using large pages when page size is 16K When the page size is 16K, use ATTR_CONTIGUOUS to map the kernel code and data sections using 2M pages. Previously, they were mapped using 16K pages. Reviewed by:markj Tested by: markj Differential Revision: https://reviews.freebsd.org/D45162 --- sys/arm64/arm64/locore.S | 26 +++--- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index f53cd365de55..fffebe8f2b02 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -516,11 +516,10 @@ booti_no_fdt: common: #if PAGE_SIZE != PAGE_SIZE_4K /* -* Create L3 pages. The kernel will be loaded at a 2M aligned -* address, however L2 blocks are too large when the page size is -* not 4k to map the kernel with such an aligned address. However, -* when the page size is larger than 4k, L2 blocks are too large to -* map the kernel with such an alignment. +* Create L3 and L3C pages. The kernel will be loaded at a 2M aligned +* address, enabling the creation of L3C pages. However, when the page +* size is larger than 4k, L2 blocks are too large to map the kernel +* with 2M alignment. */ #definePTE_SHIFT L3_SHIFT #defineBUILD_PTE_FUNC build_l3_page_pagetable @@ -784,13 +783,17 @@ LENTRY(link_l2_pagetable) LEND(link_l2_pagetable) /* - * Builds count level 3 page table entries + * Builds count level 3 page table entries. Uses ATTR_CONTIGUOUS to create + * large page (L3C) mappings when the current VA and remaining count allow + * it. * x6 = L3 table * x7 = Block attributes * x8 = VA start * x9 = PA start (trashed) * x10 = Entry count (trashed) * x11, x12 and x13 are trashed + * + * VA start (x8) modulo L3C_SIZE must equal PA start (x9) modulo L3C_SIZE. */ LENTRY(build_l3_page_pagetable) /* @@ -811,8 +814,17 @@ LENTRY(build_l3_page_pagetable) /* Only use the output address bits */ lsr x9, x9, #L3_SHIFT + /* Check if an ATTR_CONTIGUOUS mapping is possible */ +1: tst x11, #(L3C_ENTRIES - 1) + b.ne2f + cmp x10, #L3C_ENTRIES + b.lo3f + orr x12, x12, #(ATTR_CONTIGUOUS) + b 2f +3: and x12, x12, #(~ATTR_CONTIGUOUS) + /* Set the physical address for this virtual address */ -1: orr x13, x12, x9, lsl #L3_SHIFT +2: orr x13, x12, x9, lsl #L3_SHIFT /* Store the entry */ str x13, [x6, x11, lsl #3]
git: 2c65656b29fb - releng/14.1 - nfsd: Fix Link conformance with RFC8881 for delegations
The branch releng/14.1 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=2c65656b29fb803edeeda931c6771c7c22c9efac commit 2c65656b29fb803edeeda931c6771c7c22c9efac Author: Rick Macklem AuthorDate: 2024-05-04 21:30:07 + Commit: Rick Macklem CommitDate: 2024-05-13 04:49:04 + nfsd: Fix Link conformance with RFC8881 for delegations RFC8881 specifies that, when a Link operation occurs on an NFSv4, that file delegations issued to other clients must be recalled. Discovered during a recent discussion on nf...@ietf.org. Although I have not observed a problem caused by not doing the required delegation recall, it is definitely required by the RFC, so this patch makes the server do the recall. Tested during a recent NFSv4 IETF Bakeathon event. Approved by:re (cperciva) (cherry picked from commit 3f65000b6b1460a7a23cd83014bb41a68d1a8a19) (cherry picked from commit 3c414a8c2fb37ca37de454aaa145e7bcaefcaa05) --- sys/fs/nfs/nfs_var.h| 2 +- sys/fs/nfsserver/nfs_nfsdport.c | 12 +++- sys/fs/nfsserver/nfs_nfsdserv.c | 11 +-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h index 578fb3ce1340..950e0c097457 100644 --- a/sys/fs/nfs/nfs_var.h +++ b/sys/fs/nfs/nfs_var.h @@ -713,7 +713,7 @@ int nfsvno_rmdirsub(struct nameidata *, int, struct ucred *, NFSPROC_T *, struct nfsexstuff *); int nfsvno_rename(struct nameidata *, struct nameidata *, u_int32_t, u_int32_t, struct ucred *, NFSPROC_T *); -int nfsvno_link(struct nameidata *, vnode_t, struct ucred *, +int nfsvno_link(struct nameidata *, vnode_t, nfsquad_t, struct ucred *, NFSPROC_T *, struct nfsexstuff *); int nfsvno_fsync(vnode_t, u_int64_t, int, struct ucred *, NFSPROC_T *); int nfsvno_statfs(vnode_t, struct statfs *); diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index f8c2ddfd2a59..f4679309657b 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -1656,8 +1656,8 @@ out1: * Link vnode op. */ int -nfsvno_link(struct nameidata *ndp, struct vnode *vp, struct ucred *cred, -struct thread *p, struct nfsexstuff *exp) +nfsvno_link(struct nameidata *ndp, struct vnode *vp, nfsquad_t clientid, +struct ucred *cred, struct thread *p, struct nfsexstuff *exp) { struct vnode *xp; int error = 0; @@ -1672,9 +1672,11 @@ nfsvno_link(struct nameidata *ndp, struct vnode *vp, struct ucred *cred, } if (!error) { NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY); - if (!VN_IS_DOOMED(vp)) - error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd); - else + if (!VN_IS_DOOMED(vp)) { + error = nfsrv_checkremove(vp, 0, NULL, clientid, p); + if (error == 0) + error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd); + } else error = EPERM; if (ndp->ni_dvp == vp) { vrele(ndp->ni_dvp); diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index 8141ee6cbdb6..0c8bda6dc6a6 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -1797,6 +1797,7 @@ nfsrvd_link(struct nfsrv_descript *nd, int isdgram, char *bufp; u_long *hashp; struct thread *p = curthread; + nfsquad_t clientid; if (nd->nd_repstat) { nfsrv_postopattr(nd, getret, &at); @@ -1858,8 +1859,14 @@ nfsrvd_link(struct nfsrv_descript *nd, int isdgram, NULL); } } - if (!nd->nd_repstat) - nd->nd_repstat = nfsvno_link(&named, vp, nd->nd_cred, p, exp); + if (!nd->nd_repstat) { + clientid.qval = 0; + if ((nd->nd_flag & (ND_IMPLIEDCLID | ND_NFSV41)) == + (ND_IMPLIEDCLID | ND_NFSV41)) + clientid.qval = nd->nd_clientid.qval; + nd->nd_repstat = nfsvno_link(&named, vp, clientid, nd->nd_cred, + p, exp); + } if (nd->nd_flag & ND_NFSV3) getret = nfsvno_getattr(vp, &at, nd, p, 0, NULL); if (dirp) {
git: be04fec42638 - main - Import _FORTIFY_SOURCE implementation from NetBSD
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=be04fec42638f30f50b5b55fd8e3634c0fb89928 commit be04fec42638f30f50b5b55fd8e3634c0fb89928 Author: Kyle Evans AuthorDate: 2024-05-13 05:23:49 + Commit: Kyle Evans CommitDate: 2024-05-13 05:23:49 + Import _FORTIFY_SOURCE implementation from NetBSD This is a mostly-unmodified copy of the various *_chk implementations and headers from NetBSD, without yet modifying system headers to start actually including them. A future commit will also apply the needed bits to fix ssp/unistd.h. Reviewed by:imp, pauamma_gundo.com (both previous versions), kib Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D32306 --- etc/mtree/BSD.include.dist | 2 + include/Makefile | 2 +- include/ssp/Makefile | 6 ++ include/ssp/ssp.h | 91 ++ include/ssp/stdio.h| 93 ++ include/ssp/string.h | 129 include/ssp/strings.h | 67 +++ include/ssp/unistd.h | 54 +++ lib/libc/secure/Makefile.inc | 11 lib/libc/secure/Symbol.map | 18 + lib/libc/secure/fgets_chk.c| 54 +++ lib/libc/secure/gets_chk.c | 74 + lib/libc/secure/memcpy_chk.c | 53 +++ lib/libc/secure/memmove_chk.c | 47 + lib/libc/secure/memset_chk.c | 46 + lib/libc/secure/snprintf_chk.c | 56 lib/libc/secure/sprintf_chk.c | 61 + lib/libc/secure/ssp_internal.h | 37 +++ lib/libc/secure/stpcpy_chk.c | 55 lib/libc/secure/stpncpy_chk.c | 53 +++ lib/libc/secure/strcat_chk.c | 60 + lib/libc/secure/strcpy_chk.c | 54 +++ lib/libc/secure/strncat_chk.c | 70 lib/libc/secure/strncpy_chk.c | 53 +++ lib/libc/secure/vsnprintf_chk.c| 49 ++ lib/libc/secure/vsprintf_chk.c | 58 lib/libssp/Makefile| 20 +- lib/libssp/Symbol.map | 12 ++-- lib/libssp/Versions.def| 5 ++ lib/libssp/__builtin_object_size.3 | 110 +++ lib/libssp/fortify_stubs.c | 131 - lib/libssp/ssp.3 | 130 32 files changed, 1621 insertions(+), 140 deletions(-) diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.dist index a6bd5880bf61..f8c83d6dde7a 100644 --- a/etc/mtree/BSD.include.dist +++ b/etc/mtree/BSD.include.dist @@ -372,6 +372,8 @@ mac_veriexec .. .. +ssp +.. sys disk .. diff --git a/include/Makefile b/include/Makefile index 19e6beb95203..32774419f162 100644 --- a/include/Makefile +++ b/include/Makefile @@ -4,7 +4,7 @@ PACKAGE=clibs CLEANFILES= osreldate.h version -SUBDIR= arpa protocols rpcsvc rpc xlocale +SUBDIR= arpa protocols rpcsvc rpc ssp xlocale .if ${MACHINE_CPUARCH} == "amd64" SUBDIR+= i386 INCLUDE_SUBDIRS+= i386 diff --git a/include/ssp/Makefile b/include/ssp/Makefile new file mode 100644 index ..dff19f43c920 --- /dev/null +++ b/include/ssp/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +INCS= ssp.h stdio.h string.h strings.h unistd.h +INCSDIR= ${INCLUDEDIR}/ssp + +.include diff --git a/include/ssp/ssp.h b/include/ssp/ssp.h new file mode 100644 index ..35a9aeee02df --- /dev/null +++ b/include/ssp/ssp.h @@ -0,0 +1,91 @@ +/* $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp $ */ + +/*- + * + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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 + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FO
git: e55512504d01 - main - Prepare the system for _FORTIFY_SOURCE
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=e55512504d0178983978d64d67eed1cc85826523 commit e55512504d0178983978d64d67eed1cc85826523 Author: Kyle Evans AuthorDate: 2024-05-13 05:23:50 + Commit: Kyle Evans CommitDate: 2024-05-13 05:23:50 + Prepare the system for _FORTIFY_SOURCE Notably: - libc needs to #undef some of the macros from ssp/* for underlying implementations - ssp/* wants a __RENAME() macro (snatched more or less from NetBSD) There's some extra hinkiness included for read(), since libc spells it as "_read" while the rest of the world spells it "read." Reviewed by:imp, ngie Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D32307 --- contrib/netbsd-tests/lib/libc/ssp/h_gets.c | 3 +++ include/ssp/unistd.h | 8 ++-- lib/libc/Makefile | 2 ++ lib/libc/amd64/string/bcopy.c | 2 ++ lib/libc/amd64/string/bzero.c | 2 ++ lib/libc/amd64/string/strncat.c| 2 ++ lib/libc/amd64/string/strncpy.c| 2 ++ lib/libc/gen/getcwd.c | 3 ++- lib/libc/stdio/fgets.c | 2 ++ lib/libc/stdio/snprintf.c | 2 ++ lib/libc/stdio/sprintf.c | 2 ++ lib/libc/stdio/vsnprintf.c | 2 ++ lib/libc/stdio/vsprintf.c | 2 ++ lib/libc/string/bcopy.c| 5 + lib/libc/string/memset.c | 4 lib/libc/string/stpcpy.c | 2 ++ lib/libc/string/stpncpy.c | 2 ++ lib/libc/string/strcat.c | 2 ++ lib/libc/string/strncat.c | 2 ++ sys/sys/cdefs.h| 10 ++ 20 files changed, 58 insertions(+), 3 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/ssp/h_gets.c b/contrib/netbsd-tests/lib/libc/ssp/h_gets.c index f73d29a08bf3..9da01cab8eb4 100644 --- a/contrib/netbsd-tests/lib/libc/ssp/h_gets.c +++ b/contrib/netbsd-tests/lib/libc/ssp/h_gets.c @@ -34,6 +34,9 @@ __RCSID("$NetBSD: h_gets.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $"); #include #ifdef __FreeBSD__ +/* _FORTIFY_SOURCE, at the very least, may #define a gets() macro. */ +#undef gets + /* * We want to test the gets() implementation, but cannot simply link against * the gets symbol because it is not in the default version. (We've made it diff --git a/include/ssp/unistd.h b/include/ssp/unistd.h index 2414e2baa96b..bcd3664116cc 100644 --- a/include/ssp/unistd.h +++ b/include/ssp/unistd.h @@ -39,8 +39,12 @@ #if __SSP_FORTIFY_LEVEL > 0 __BEGIN_DECLS -__ssp_redirect0(ssize_t, read, (int __fd, void *__buf, size_t __len), \ -(__fd, __buf, __len)); +#ifndef _FORTIFY_SOURCE_read +#define_FORTIFY_SOURCE_readread +#endif + +__ssp_redirect0(ssize_t, _FORTIFY_SOURCE_read, (int __fd, void *__buf, +size_t __len), (__fd, __buf, __len)); __ssp_redirect(ssize_t, readlink, (const char *__restrict __path, \ char *__restrict __buf, size_t __len), (__path, __buf, __len)); diff --git a/lib/libc/Makefile b/lib/libc/Makefile index 674986a7e065..c70e57498771 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -19,6 +19,8 @@ LIBC_ARCH=${M} LIBC_ARCH=${MACHINE_CPUARCH} .endif +CFLAGS+=-D_FORTIFY_SOURCE_read=_read + # All library objects contain FreeBSD revision strings by default; they may be # excluded as a space-saving measure. To produce a library that does # not contain these strings, add -DSTRIP_FBSDID (see ) to CFLAGS diff --git a/lib/libc/amd64/string/bcopy.c b/lib/libc/amd64/string/bcopy.c index 868567711e8b..0dee529fb9df 100644 --- a/lib/libc/amd64/string/bcopy.c +++ b/lib/libc/amd64/string/bcopy.c @@ -4,6 +4,8 @@ #include +#undef bcopy /* _FORTIFY_SOURCE */ + void bcopy(const void *src, void *dst, size_t len) { diff --git a/lib/libc/amd64/string/bzero.c b/lib/libc/amd64/string/bzero.c index 92adb2bb4f0e..d82f3061865b 100644 --- a/lib/libc/amd64/string/bzero.c +++ b/lib/libc/amd64/string/bzero.c @@ -4,6 +4,8 @@ #include +#undef bzero /* _FORTIFY_SOURCE */ + void bzero(void *b, size_t len) { diff --git a/lib/libc/amd64/string/strncat.c b/lib/libc/amd64/string/strncat.c index 33b278ac5e04..2c63ab50b3c3 100644 --- a/lib/libc/amd64/string/strncat.c +++ b/lib/libc/amd64/string/strncat.c @@ -8,6 +8,8 @@ #include +#undef strncat /* _FORTIFY_SOURCE */ + void *__memccpy(void *restrict, const void *restrict, int, size_t); char * diff --git a/lib/libc/amd64/string/strncpy.c b/lib/libc/amd64/string/strncpy.c index b3d868787fbe..0e7a58222aa8 100644 --- a/lib/libc/amd64/string/strncpy.c +++ b/lib/libc/amd64/string/strncpy.c @@ -29,6 +29,8 @@ #include #include +#undef strncpy /* _FORTIFY_SOURCE */ + char *__stpncpy(char *restrict, const char *restrict, size_t); char * diff
git: 9bfd3b4076a7 - main - Add a build knob for _FORTIFY_SOURCE
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=9bfd3b4076a7b0dfd27ab22318e5113dc84fea28 commit 9bfd3b4076a7b0dfd27ab22318e5113dc84fea28 Author: Kyle Evans AuthorDate: 2024-05-13 05:23:50 + Commit: Kyle Evans CommitDate: 2024-05-13 05:23:50 + Add a build knob for _FORTIFY_SOURCE In the future, we will Default to _FORTIFY_SOURCE=2 if SSP is enabled, otherwise default to _FORTIFY_SOURCE=0. For now we default it to 0 unconditionally to ease bisect across older versions without the new symbols, and we'll put out a call for testing. include/*.h include their ssp/*.h equivalents as needed based on the knob. Programs and users are allowed to override FORTIFY_SOURCE in their Makefiles or src.conf/make.conf to force it off. Reviewed by:des, markj Relnotes: yes Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D32308 --- include/stdio.h | 3 ++ include/string.h| 3 ++ include/strings.h | 3 ++ include/unistd.h| 4 +++ lib/libthr/Makefile | 3 ++ libexec/rtld-elf/Makefile | 4 +++ share/man/man7/security.7 | 75 + share/mk/bsd.sys.mk | 7 tools/build/options/WITHOUT_SSP | 3 ++ tools/build/options/WITH_SSP| 3 ++ 10 files changed, 108 insertions(+) diff --git a/include/stdio.h b/include/stdio.h index fe7a6f7d6f82..30bc638082d8 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -530,4 +530,7 @@ extern int __isthreaded; __END_DECLS __NULLABILITY_PRAGMA_POP +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 +#include +#endif #endif /* !_STDIO_H_ */ diff --git a/include/string.h b/include/string.h index 597308020cdb..a595f6e3e260 100644 --- a/include/string.h +++ b/include/string.h @@ -168,4 +168,7 @@ errno_t memset_s(void *, rsize_t, int, rsize_t); #endif /* __EXT1_VISIBLE */ __END_DECLS +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 +#include +#endif #endif /* _STRING_H_ */ diff --git a/include/strings.h b/include/strings.h index fde007186e04..6fe6a09e7dd3 100644 --- a/include/strings.h +++ b/include/strings.h @@ -68,4 +68,7 @@ intstrncasecmp(const char *, const char *, size_t) __pure; #endif __END_DECLS +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 +#include +#endif #endif /* _STRINGS_H_ */ diff --git a/include/unistd.h b/include/unistd.h index e4e5c62fbb67..59738cbf6e68 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -37,6 +37,10 @@ #include #include +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 +#include +#endif + #ifndef _GID_T_DECLARED typedef__gid_t gid_t; #define_GID_T_DECLARED diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile index a5bf5da44170..85c028f521a1 100644 --- a/lib/libthr/Makefile +++ b/lib/libthr/Makefile @@ -11,6 +11,9 @@ LDFLAGS+= -Wl,--rpath=/usr/lib${COMPAT_libcompat} .include MK_SSP=no +# SSP forced off already implies FORTIFY_SOURCE=0, but we must make sure that +# one cannot turn it back on. +FORTIFY_SOURCE=0 LIB=thr SHLIB_MAJOR= 3 diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile index 37c3840538d5..864448ad782a 100644 --- a/libexec/rtld-elf/Makefile +++ b/libexec/rtld-elf/Makefile @@ -15,6 +15,10 @@ MK_UBSAN=no .include +# SSP forced off already implies FORTIFY_SOURCE=0, but we must make sure that +# one cannot turn it back on. +FORTIFY_SOURCE=0 + .if !defined(NEED_COMPAT) CONFS= libmap.conf .endif diff --git a/share/man/man7/security.7 b/share/man/man7/security.7 index ccbeeb4575ce..2e690e35d534 100644 --- a/share/man/man7/security.7 +++ b/share/man/man7/security.7 @@ -939,6 +939,81 @@ option that SSH allows in its .Pa authorized_keys file to make the key only usable to entities logging in from specific machines. +.Sh STACK OVERFLOW PROTECTION +.Fx +supports stack overflow protection using the Stack Smashing Protector +.Pq SSP +compiler feature. +In userland, SSP adds a per-process randomized canary at the end of every stack +frame which is checked for corruption upon return from the function. +In the kernel, a single randomized canary is used globally except on aarch64, +which has a +.Dv PERTHREAD_SSP +.Xr config 8 +option to enable per-thread randomized canaries. +If stack corruption is detected, then the process aborts to avoid potentially +malicious execution as a result of the corruption. +SSP may be enabled or disabled when building +.Fx +base with the +.Xr src.conf 5 +SSP knob. +.Pp +When +.Va WITH_SSP +is enabled, which is the default, world is built with the +.Fl fstack-protector-strong +compiler option. +The kernel is built with the +.Fl fstack-protector +option. +.Pp +In addition to SSP, a +.Dq FORTIFY_SOURCE +implementation is supported up to level 2 by defini