]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 5.15
authorSasha Levin <sashal@kernel.org>
Mon, 28 Oct 2024 00:24:30 +0000 (20:24 -0400)
committerSasha Levin <sashal@kernel.org>
Mon, 28 Oct 2024 00:24:30 +0000 (20:24 -0400)
Signed-off-by: Sasha Levin <sashal@kernel.org>
queue-5.15/selinux-improve-error-checking-in-sel_write_load.patch [new file with mode: 0644]
queue-5.15/serial-protect-uart_port_dtr_rts-in-uart_shutdown-to.patch [new file with mode: 0644]
queue-5.15/series

diff --git a/queue-5.15/selinux-improve-error-checking-in-sel_write_load.patch b/queue-5.15/selinux-improve-error-checking-in-sel_write_load.patch
new file mode 100644 (file)
index 0000000..185ca92
--- /dev/null
@@ -0,0 +1,95 @@
+From 43df2a14413b91159db19f5dd68b979d1975b2dc Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 25 Oct 2024 11:20:57 -0300
+Subject: selinux: improve error checking in sel_write_load()
+
+From: Paul Moore <paul@paul-moore.com>
+
+[ Upstream commit 42c773238037c90b3302bf37a57ae3b5c3f6004a ]
+
+Move our existing input sanity checking to the top of sel_write_load()
+and add a check to ensure the buffer size is non-zero.
+
+Move a local variable initialization from the declaration to before it
+is used.
+
+Minor style adjustments.
+
+Reported-by: Sam Sun <samsun1006219@gmail.com>
+Signed-off-by: Paul Moore <paul@paul-moore.com>
+[cascardo: keep fsi initialization at its declaration point as it is used earlier]
+Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ security/selinux/selinuxfs.c | 27 ++++++++++++++-------------
+ 1 file changed, 14 insertions(+), 13 deletions(-)
+
+diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
+index f2f6203e0fff5..13be7826ae804 100644
+--- a/security/selinux/selinuxfs.c
++++ b/security/selinux/selinuxfs.c
+@@ -619,6 +619,13 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
+       ssize_t length;
+       void *data = NULL;
++      /* no partial writes */
++      if (*ppos)
++              return -EINVAL;
++      /* no empty policies */
++      if (!count)
++              return -EINVAL;
++
+       mutex_lock(&fsi->state->policy_mutex);
+       length = avc_has_perm(&selinux_state,
+@@ -627,26 +634,21 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
+       if (length)
+               goto out;
+-      /* No partial writes. */
+-      length = -EINVAL;
+-      if (*ppos != 0)
+-              goto out;
+-
+-      length = -ENOMEM;
+       data = vmalloc(count);
+-      if (!data)
++      if (!data) {
++              length = -ENOMEM;
+               goto out;
+-
+-      length = -EFAULT;
+-      if (copy_from_user(data, buf, count) != 0)
++      }
++      if (copy_from_user(data, buf, count) != 0) {
++              length = -EFAULT;
+               goto out;
++      }
+       length = security_load_policy(fsi->state, data, count, &load_state);
+       if (length) {
+               pr_warn_ratelimited("SELinux: failed to load policy\n");
+               goto out;
+       }
+-
+       length = sel_make_policy_nodes(fsi, load_state.policy);
+       if (length) {
+               pr_warn_ratelimited("SELinux: failed to initialize selinuxfs\n");
+@@ -655,13 +657,12 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
+       }
+       selinux_policy_commit(fsi->state, &load_state);
+-
+       length = count;
+-
+       audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
+               "auid=%u ses=%u lsm=selinux res=1",
+               from_kuid(&init_user_ns, audit_get_loginuid(current)),
+               audit_get_sessionid(current));
++
+ out:
+       mutex_unlock(&fsi->state->policy_mutex);
+       vfree(data);
+-- 
+2.43.0
+
diff --git a/queue-5.15/serial-protect-uart_port_dtr_rts-in-uart_shutdown-to.patch b/queue-5.15/serial-protect-uart_port_dtr_rts-in-uart_shutdown-to.patch
new file mode 100644 (file)
index 0000000..ccb8aac
--- /dev/null
@@ -0,0 +1,67 @@
+From db71acf424c53d642c7f163ba18738efee9d3fbe Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 25 Oct 2024 11:05:48 +0000
+Subject: serial: protect uart_port_dtr_rts() in uart_shutdown() too
+
+From: Jiri Slaby (SUSE) <jirislaby@kernel.org>
+
+[ Upstream commit 602babaa84d627923713acaf5f7e9a4369e77473 ]
+
+Commit af224ca2df29 (serial: core: Prevent unsafe uart port access, part
+3) added few uport == NULL checks. It added one to uart_shutdown(), so
+the commit assumes, uport can be NULL in there. But right after that
+protection, there is an unprotected "uart_port_dtr_rts(uport, false);"
+call. That is invoked only if HUPCL is set, so I assume that is the
+reason why we do not see lots of these reports.
+
+Or it cannot be NULL at this point at all for some reason :P.
+
+Until the above is investigated, stay on the safe side and move this
+dereference to the if too.
+
+I got this inconsistency from Coverity under CID 1585130. Thanks.
+
+Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
+Cc: Peter Hurley <peter@hurleysoftware.com>
+Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Link: https://lore.kernel.org/r/20240805102046.307511-3-jirislaby@kernel.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+[Adapted over commit 5701cb8bf50e ("tty: Call ->dtr_rts() parameter
+active consistently") not in the tree]
+Signed-off-by: Tomas Krcka <krckatom@amazon.de>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/tty/serial/serial_core.c | 16 +++++++++-------
+ 1 file changed, 9 insertions(+), 7 deletions(-)
+
+diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
+index 7cd12ea88c0b0..404354727d194 100644
+--- a/drivers/tty/serial/serial_core.c
++++ b/drivers/tty/serial/serial_core.c
+@@ -286,14 +286,16 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
+               /*
+                * Turn off DTR and RTS early.
+                */
+-              if (uport && uart_console(uport) && tty) {
+-                      uport->cons->cflag = tty->termios.c_cflag;
+-                      uport->cons->ispeed = tty->termios.c_ispeed;
+-                      uport->cons->ospeed = tty->termios.c_ospeed;
+-              }
++              if (uport) {
++                      if (uart_console(uport) && tty) {
++                              uport->cons->cflag = tty->termios.c_cflag;
++                              uport->cons->ispeed = tty->termios.c_ispeed;
++                              uport->cons->ospeed = tty->termios.c_ospeed;
++                      }
+-              if (!tty || C_HUPCL(tty))
+-                      uart_port_dtr_rts(uport, 0);
++                      if (!tty || C_HUPCL(tty))
++                              uart_port_dtr_rts(uport, 0);
++              }
+               uart_port_shutdown(port);
+       }
+-- 
+2.43.0
+
index 903f80644221e6cc54fe26f68a4917e89e087204..984f3dc00a7da5735bfcd0be9ee4f37e2b0fc291 100644 (file)
@@ -63,3 +63,5 @@ posix-clock-posix-clock-fix-unbalanced-locking-in-pc.patch
 bpf-perf-fix-perf_event_detach_bpf_prog-error-handli.patch
 alsa-firewire-lib-avoid-division-by-zero-in-apply_co.patch
 alsa-hda-realtek-update-default-depop-procedure.patch
+selinux-improve-error-checking-in-sel_write_load.patch
+serial-protect-uart_port_dtr_rts-in-uart_shutdown-to.patch