Skip to content

Commit 5e722b2

Browse files
WOnder93gregkh
authored andcommitted
serial: core: fix suspicious security_locked_down() call
The commit that added this check did so in a very strange way - first security_locked_down() is called, its value stored into retval, and if it's nonzero, then an additional check is made for (change_irq || change_port), and if this is true, the function returns. However, if the goto exit branch is not taken, the code keeps the retval value and continues executing the function. Then, depending on whether uport->ops->verify_port is set, the retval value may or may not be reset to zero and eventually the error value from security_locked_down() may abort the function a few lines below. I will go out on a limb and assume that this isn't the intended behavior and that an error value from security_locked_down() was supposed to abort the function only in case (change_irq || change_port) is true. Note that security_locked_down() should be called last in any series of checks, since the SELinux implementation of this hook will do a check against the policy and generate an audit record in case of denial. If the operation was to carry on after calling security_locked_down(), then the SELinux denial record would be bogus. See commit 59438b4 ("security,lockdown,selinux: implement SELinux lockdown") for how SELinux implements this hook. Fixes: 794edf3 ("lockdown: Lock down TIOCSSERIAL") Acked-by: Kees Cook <[email protected]> Signed-off-by: Ondrej Mosnacek <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3ddb4ce commit 5e722b2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/tty/serial/serial_core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,11 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
863863
goto check_and_exit;
864864
}
865865

866-
retval = security_locked_down(LOCKDOWN_TIOCSSERIAL);
867-
if (retval && (change_irq || change_port))
868-
goto exit;
866+
if (change_irq || change_port) {
867+
retval = security_locked_down(LOCKDOWN_TIOCSSERIAL);
868+
if (retval)
869+
goto exit;
870+
}
869871

870872
/*
871873
* Ask the low level driver to verify the settings.

0 commit comments

Comments
 (0)