git: 50fe2c32d568 - stable/13 - linux(4): Use the copyin_sigset() in the remaining places

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Fri, 17 Jun 2022 19:41:30 UTC
The branch stable/13 has been updated by dchagin:

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

commit 50fe2c32d568f9e8db081327303e839769ae9c31
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-05-30 16:59:45 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:35:39 +0000

    linux(4): Use the copyin_sigset() in the remaining places
    
    MFC after:              2 weeks
    
    (cherry picked from commit 5e872c279aecd169df34602669ee9c86ae9e9f18)
---
 sys/compat/linux/linux_misc.c   | 26 +++++++-------------------
 sys/compat/linux/linux_signal.c | 36 ++++++++++++++----------------------
 2 files changed, 21 insertions(+), 41 deletions(-)

diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 64e6b03c5451..b041c0467345 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -2420,7 +2420,6 @@ linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds,
 {
 	struct timeval utv, tv0, tv1, *tvp;
 	struct l_pselect6arg lpse6;
-	l_sigset_t l_ss;
 	sigset_t *ssp;
 	sigset_t ss;
 	int error;
@@ -2430,16 +2429,10 @@ linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds,
 		error = copyin(sig, &lpse6, sizeof(lpse6));
 		if (error != 0)
 			return (error);
-		if (lpse6.ss_len != sizeof(l_ss))
-			return (EINVAL);
-		if (lpse6.ss != 0) {
-			error = copyin(PTRIN(lpse6.ss), &l_ss,
-			    sizeof(l_ss));
-			if (error != 0)
-				return (error);
-			linux_to_bsd_sigset(&l_ss, &ss);
-			ssp = &ss;
-		}
+		error = linux_copyin_sigset(PTRIN(lpse6.ss),
+		    lpse6.ss_len, &ss, &ssp);
+		if (error != 0)
+		    return (error);
 	} else
 		ssp = NULL;
 
@@ -2530,7 +2523,6 @@ linux_common_ppoll(struct thread *td, struct pollfd *fds, uint32_t nfds,
 	struct timespec ts0, ts1;
 	struct pollfd stackfds[32];
 	struct pollfd *kfds;
- 	l_sigset_t l_ss;
  	sigset_t *ssp;
  	sigset_t ss;
  	int error;
@@ -2538,13 +2530,9 @@ linux_common_ppoll(struct thread *td, struct pollfd *fds, uint32_t nfds,
 	if (kern_poll_maxfds(nfds))
 		return (EINVAL);
 	if (sset != NULL) {
-		if (ssize != sizeof(l_ss))
-			return (EINVAL);
-		error = copyin(sset, &l_ss, sizeof(l_ss));
-		if (error)
-			return (error);
-		linux_to_bsd_sigset(&l_ss, &ss);
-		ssp = &ss;
+		error = linux_copyin_sigset(sset, ssize, &ss, &ssp);
+		if (error != 0)
+		    return (error);
 	} else
 		ssp = NULL;
 	if (tsp != NULL)
diff --git a/sys/compat/linux/linux_signal.c b/sys/compat/linux/linux_signal.c
index 9aecb8497f3b..a5f5d86d8c5d 100644
--- a/sys/compat/linux/linux_signal.c
+++ b/sys/compat/linux/linux_signal.c
@@ -266,11 +266,10 @@ linux_rt_sigaction(struct thread *td, struct linux_rt_sigaction_args *args)
 }
 
 static int
-linux_do_sigprocmask(struct thread *td, int how, l_sigset_t *new,
+linux_do_sigprocmask(struct thread *td, int how, sigset_t *new,
 		     l_sigset_t *old)
 {
-	sigset_t omask, nmask;
-	sigset_t *nmaskp;
+	sigset_t omask;
 	int error;
 
 	td->td_retval[0] = 0;
@@ -288,12 +287,7 @@ linux_do_sigprocmask(struct thread *td, int how, l_sigset_t *new,
 	default:
 		return (EINVAL);
 	}
-	if (new != NULL) {
-		linux_to_bsd_sigset(new, &nmask);
-		nmaskp = &nmask;
-	} else
-		nmaskp = NULL;
-	error = kern_sigprocmask(td, how, nmaskp, &omask, 0);
+	error = kern_sigprocmask(td, how, new, &omask, 0);
 	if (error == 0 && old != NULL)
 		bsd_to_linux_sigset(&omask, old);
 
@@ -305,15 +299,17 @@ int
 linux_sigprocmask(struct thread *td, struct linux_sigprocmask_args *args)
 {
 	l_osigset_t mask;
-	l_sigset_t set, oset;
+	l_sigset_t lset, oset;
+	sigset_t set;
 	int error;
 
 	if (args->mask != NULL) {
 		error = copyin(args->mask, &mask, sizeof(l_osigset_t));
 		if (error)
 			return (error);
-		LINUX_SIGEMPTYSET(set);
-		set.__mask = mask;
+		LINUX_SIGEMPTYSET(lset);
+		lset.__mask = mask;
+		linux_to_bsd_sigset(&lset, &set);
 	}
 
 	error = linux_do_sigprocmask(td, args->how,
@@ -332,20 +328,16 @@ linux_sigprocmask(struct thread *td, struct linux_sigprocmask_args *args)
 int
 linux_rt_sigprocmask(struct thread *td, struct linux_rt_sigprocmask_args *args)
 {
-	l_sigset_t set, oset;
+	l_sigset_t oset;
+	sigset_t set, *pset;
 	int error;
 
-	if (args->sigsetsize != sizeof(l_sigset_t))
+	error = linux_copyin_sigset(args->mask, args->sigsetsize,
+	    &set, &pset);
+	if (error != 0)
 		return (EINVAL);
 
-	if (args->mask != NULL) {
-		error = copyin(args->mask, &set, sizeof(l_sigset_t));
-		if (error)
-			return (error);
-	}
-
-	error = linux_do_sigprocmask(td, args->how,
-				     args->mask ? &set : NULL,
+	error = linux_do_sigprocmask(td, args->how, pset,
 				     args->omask ? &oset : NULL);
 
 	if (args->omask != NULL && !error) {