Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 May 2023 23:37:46 GMT
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 8e63e787abbd - main - pmc: Initialise and check the pm_flags field for CONFIGURELOG
Message-ID:  <202305302337.34UNbknP056835@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jrtc27:

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

commit 8e63e787abbd69d29e55e2e0b2aa0aa624339f3b
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2023-05-30 23:15:24 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-05-30 23:15:24 +0000

    pmc: Initialise and check the pm_flags field for CONFIGURELOG
    
    Whilst the former is not breaking, the latter is, and so this will be
    followed by a bump to the pmc major version. This will allow the flags
    to actually be usable in future, as otherwise we cannot distinguish
    uninitialised stack junk from a deliberately-initialised value.
    
    Reviewed by:    jhb, mhorne
    Differential Revision:  https://reviews.freebsd.org/D40049
---
 lib/libpmc/libpmc.c       | 1 +
 share/man/man4/hwpmc.4    | 6 ++++++
 sys/dev/hwpmc/hwpmc_mod.c | 6 ++++++
 3 files changed, 13 insertions(+)

diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c
index f43fd5d0eac9..4a8e02fafbfe 100644
--- a/lib/libpmc/libpmc.c
+++ b/lib/libpmc/libpmc.c
@@ -1195,6 +1195,7 @@ pmc_configure_logfile(int fd)
 {
 	struct pmc_op_configurelog cla;
 
+	cla.pm_flags = 0;
 	cla.pm_logfd = fd;
 	if (PMC_CALL(CONFIGURELOG, &cla) < 0)
 		return (-1);
diff --git a/share/man/man4/hwpmc.4 b/share/man/man4/hwpmc.4
index 806c2ee701c5..4500e168b021 100644
--- a/share/man/man4/hwpmc.4
+++ b/share/man/man4/hwpmc.4
@@ -598,6 +598,12 @@ An invalid CPU number was passed in for a
 .Dv PMC_OP_GETPMCINFO
 operation.
 .It Bq Er EINVAL
+The
+.Ar pm_flags
+argument to a
+.Dv PMC_OP_CONFIGURELOG
+request contained unknown flags.
+.It Bq Er EINVAL
 A
 .Dv PMC_OP_CONFIGURELOG
 request to de-configure a log file was issued without a log file
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index c6ec33f88e3c..29518152760f 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -3438,6 +3438,12 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
 			break;
 		}
 
+		/* No flags currently implemented */
+		if (cl.pm_flags != 0) {
+			error = EINVAL;
+			break;
+		}
+
 		/* mark this process as owning a log file */
 		p = td->td_proc;
 		if ((po = pmc_find_owner_descriptor(p)) == NULL)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202305302337.34UNbknP056835>