From nobody Fri Jun 17 19:29:06 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id DBE67847726; Fri, 17 Jun 2022 19:29:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LPpxw23ppz3Gpf; Fri, 17 Jun 2022 19:29:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=76p3w/p7q5/PsZhvNMhjPnIucXe5tU0/51zMHjxWwnw=; b=NwJY3C1vmcQ/zkNOy8y0jvnCmSBhUxPLEJD68Kgt+iAuxGyZxtrRnKm+EWQVCj8iVoOMrZ Wzp+ESV26j7P9HoB2q0fetAeybALjalrpLoqxZL0bFgfjM9Bzbd4Fn9t13tdnQRYxzp/EG UIJUzKDR1VniTPyTw3s5Zx1bN4wm97EbmYrHc0ZLY9Xo2VQkOfX6tNr2BG999yN7feuq/h XOavckyp4pwfTv0I3yECAYucWCrv/v8XqE9+bapFAuhGLwgN+OwtpIfQBG9gED1VWdKaCw cwnwRpzduUv9DhWN7DPwJt9A4iWklO5fFFTzrU58ize8kSkUGGt+KwZ2b+JxGA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B527525878; Fri, 17 Jun 2022 19:29:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25HJT6do096968; Fri, 17 Jun 2022 19:29:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJT68p096967; Fri, 17 Jun 2022 19:29:06 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:29:06 GMT Message-Id: <202206171929.25HJT68p096967@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: fc13bfeae58f - stable/13 - linux(4): Properly convert linux siginfo to native siginfo add input validation. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fc13bfeae58f1be3d03971caa9a3078cdf66878c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=76p3w/p7q5/PsZhvNMhjPnIucXe5tU0/51zMHjxWwnw=; b=vIIAFCnQO3dHQy1Q5nhmoZCmuaLpSDIEq3ys9IBNXJHO0jr43shNLEAhHOb/T6aq6OXK8U mefytlQXNAl+MlwW4jOOxI5HEmRHweLh4PBgh4IE00fG9PaWboKRRwAhH9VqdnAn9xPkUd Pd4nEuZtrdRcBtRvZLMnxoQCqa+93FW634qXrfAS6Ne8Xu4VPZ612MbQGKKlrqnI6/6hEJ yWyCP1ktaeqBBGZ1xwzdxDh97QZ5ouozBbyeyWM0pwEMWrvdIVrR0TPCqXj6vE4BdGenre CL/LyBL4UOFwcwmZ5UT/Q9O6flYpGwIvyLjBLQRVhimJP9OXWk5rJxRN2Wtx0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494148; a=rsa-sha256; cv=none; b=oEDOmwfh1m5Gl46HmqWnYMr7D4l4Hghg2zsJzpp+0rziZAVyA/LurhAu9NUVUygum9S2By EWucc/etoW7wx7Fs/53DNwX743/wv4GV+fd3SOTR/HdG3ic5T1Q7lBvQ0RK0GzBFofAz89 YC6zqgkWQ2tYHQmFKR55YGItsqrOzBS2a8UFVEB1WFLKSgDytVU2vDX9Dez2JvqRNVji0O wTcPpmD+IR32YBfq/LtoFa4bB8BVaQ3PNktFFwjDGI5SAfZ+k59HMrqKgRdtbMmoBqDrww gEwwTOGjOsYg7JGqmssSmw+aUty6ix/yBv2Hbh6+6uHjIpoOsMFZR4DfZ4l41g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=fc13bfeae58f1be3d03971caa9a3078cdf66878c commit fc13bfeae58f1be3d03971caa9a3078cdf66878c Author: Dmitry Chagin AuthorDate: 2021-06-07 02:55:34 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:28:00 +0000 linux(4): Properly convert linux siginfo to native siginfo add input validation. MFC after: 2 weeks (cherry picked from commit 9c1045ff00935a4bb0592d8c00ca1981d3e6eb8b) --- sys/compat/linux/linux_mib.h | 1 + sys/compat/linux/linux_signal.c | 59 ++++++++++++++++++++++++++++++----------- sys/compat/linux/linux_signal.h | 3 ++- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/sys/compat/linux/linux_mib.h b/sys/compat/linux/linux_mib.h index 8f2b87e5f3a6..4d2578f91990 100644 --- a/sys/compat/linux/linux_mib.h +++ b/sys/compat/linux/linux_mib.h @@ -59,6 +59,7 @@ int linux_kernver(struct thread *td); #define LINUX_KERNVER_2004000 LINUX_KERNVER(2,4,0) #define LINUX_KERNVER_2006000 LINUX_KERNVER(2,6,0) +#define LINUX_KERNVER_2006039 LINUX_KERNVER(2,6,39) #define linux_use26(t) (linux_kernver(t) >= LINUX_KERNVER_2006000) diff --git a/sys/compat/linux/linux_signal.c b/sys/compat/linux/linux_signal.c index 50dae4d90d43..467d2810a228 100644 --- a/sys/compat/linux/linux_signal.c +++ b/sys/compat/linux/linux_signal.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #endif +#include #include #include #include @@ -656,17 +657,40 @@ siginfo_to_lsiginfo(const siginfo_t *si, l_siginfo_t *lsi, l_int sig) } } -void -lsiginfo_to_ksiginfo(const l_siginfo_t *lsi, ksiginfo_t *ksi, int sig) +int +lsiginfo_to_siginfo(struct thread *td, const l_siginfo_t *lsi, + siginfo_t *si, int sig) { - ksi->ksi_signo = sig; - ksi->ksi_code = lsi->lsi_code; /* XXX. Convert. */ - ksi->ksi_pid = lsi->lsi_pid; - ksi->ksi_uid = lsi->lsi_uid; - ksi->ksi_status = lsi->lsi_status; - ksi->ksi_addr = PTRIN(lsi->lsi_addr); - ksi->ksi_info.si_value.sival_int = lsi->lsi_int; + switch (lsi->lsi_code) { + case LINUX_SI_TKILL: + if (linux_kernver(td) >= LINUX_KERNVER_2006039) { + linux_msg(td, "SI_TKILL forbidden since 2.6.39"); + return (EPERM); + } + si->si_code = SI_LWP; + case LINUX_SI_QUEUE: + si->si_code = SI_QUEUE; + break; + case LINUX_SI_TIMER: + si->si_code = SI_TIMER; + break; + case LINUX_SI_MESGQ: + si->si_code = SI_MESGQ; + break; + case LINUX_SI_ASYNCIO: + si->si_code = SI_ASYNCIO; + break; + default: + si->si_code = lsi->lsi_code; + break; + } + + si->si_signo = sig; + si->si_pid = td->td_proc->p_pid; + si->si_uid = td->td_ucred->cr_ruid; + si->si_value.sival_ptr = PTRIN(lsi->lsi_value.sival_ptr); + return (0); } int @@ -686,9 +710,14 @@ linux_rt_sigqueueinfo(struct thread *td, struct linux_rt_sigqueueinfo_args *args return (error); if (linfo.lsi_code >= 0) + /* SI_USER, SI_KERNEL */ return (EPERM); sig = linux_to_bsd_signal(args->sig); + ksiginfo_init(&ksi); + error = lsiginfo_to_siginfo(td, &linfo, &ksi.ksi_info, sig); + if (error != 0) + return (error); error = ESRCH; if ((p = pfind_any(args->pid)) != NULL) { @@ -697,9 +726,6 @@ linux_rt_sigqueueinfo(struct thread *td, struct linux_rt_sigqueueinfo_args *args PROC_UNLOCK(p); return (error); } - - ksiginfo_init(&ksi); - lsiginfo_to_ksiginfo(&linfo, &ksi, sig); error = tdsendsignal(p, NULL, sig, &ksi); PROC_UNLOCK(p); } @@ -726,13 +752,16 @@ linux_rt_tgsigqueueinfo(struct thread *td, struct linux_rt_tgsigqueueinfo_args * if (linfo.lsi_code >= 0) return (EPERM); + sig = linux_to_bsd_signal(args->sig); + ksiginfo_init(&ksi); + error = lsiginfo_to_siginfo(td, &linfo, &ksi.ksi_info, sig); + if (error != 0) + return (error); + tds = linux_tdfind(td, args->tid, args->tgid); if (tds == NULL) return (ESRCH); - sig = linux_to_bsd_signal(args->sig); - ksiginfo_init(&ksi); - lsiginfo_to_ksiginfo(&linfo, &ksi, sig); return (linux_do_tkill(td, tds, &ksi)); } diff --git a/sys/compat/linux/linux_signal.h b/sys/compat/linux/linux_signal.h index 5df74fb71029..bb34613fa2be 100644 --- a/sys/compat/linux/linux_signal.h +++ b/sys/compat/linux/linux_signal.h @@ -46,6 +46,7 @@ int linux_do_sigaction(struct thread *, int, l_sigaction_t *, l_sigaction_t *); void ksiginfo_to_lsiginfo(const ksiginfo_t *ksi, l_siginfo_t *lsi, l_int sig); void siginfo_to_lsiginfo(const siginfo_t *si, l_siginfo_t *lsi, l_int sig); -void lsiginfo_to_ksiginfo(const l_siginfo_t *lsi, ksiginfo_t *ksi, int sig); +int lsiginfo_to_siginfo(struct thread *td, const l_siginfo_t *lsi, + siginfo_t *si, int sig); #endif /* _LINUX_SIGNAL_H_ */