Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2725485pxj; Mon, 31 May 2021 09:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5XBgfC1vMmC5mU+mpkXnsHH2YMMn1u+m6JOW/948ucDzNgY8TVt3p9CQ0y0Z0ohcHli67 X-Received: by 2002:a05:6e02:12a6:: with SMTP id f6mr3035939ilr.121.1622477437956; Mon, 31 May 2021 09:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622477437; cv=none; d=google.com; s=arc-20160816; b=kCYS3Vh6Oe+FmVPML0yqjIZFph9IsQclhpy/hD+6mQlu3eo9BSNR/J9auDz7wVeHcr 6wHbahqVXH/AqcqR0cLdrweaFgLrrDjkQyzsLbd476Q9PWjk3gecauCLNseGVqg/u5+G t/3xFBQxQuY1h+fpci1M8OLI5q4nC7JYMH3Z/56BX7fn8uHbo8CpfNRJiFvTM+fs2AUb Td8iKiuIIorHcsVAFRxWK26rw65zyFZrI1uqNElcNF5OMzcvjUiclo8jgntqyXqLjP0f OuRgdoEwa0puR9199d/4R0dFLImy4vTchM3I8DZ+lryVrXFrDwVK8mAtM631f1nrv0wk UQNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WPIvVAOSdHxO1XnBinrdVXrfePYurjVXiLsAZMVwXZg=; b=JIVTEyILuVMVeVRJDumjGTbFSd10eRtCNWYmmf9WlGP2C7t1zMMz7DN5NFp0mHs/tH ZPWoEX7J8VBhIEgWx5dihQL6qNHrnlrmc/VbYR6CyEEf7jF72nRWY+14RODvDU4Ro5zL rEmGB3+UZPmkUjPeuOirVvpc8Jf0f53VxoyPf2X+FuhNLpEct6NUfEl8ShmtgtTAn2Q3 pBjIYnQaCLnQXMLpXZ/kP9g+Yb19PKe6dGWwQ79E5vr5pxT6Izg9r6bonVq2MVfKtvZV /IWZWydKOJ2lnhHBq6vXHOTpoVB8ivMDXAY3PHGUuDmUqNbpk58OlT5bRrTt3D6zyhbU uAkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RJZ2a8vG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si7051044ilg.125.2021.05.31.09.10.24; Mon, 31 May 2021 09:10:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RJZ2a8vG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234441AbhEaQKM (ORCPT + 99 others); Mon, 31 May 2021 12:10:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233216AbhEaOhT (ORCPT ); Mon, 31 May 2021 10:37:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CF86E616EC; Mon, 31 May 2021 13:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469089; bh=Bzk3q18Rykvj7pc36KDsfBnTnyDHicERbODMBtkjrJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJZ2a8vG5V1T9kgAuDKcrb6oRefP/mEWLxXo6TiSAIHfkuhTViOo4SIlJSk0U62Np WFpCSCs9Z1bdZT5DAe5rUH7u79FiDO4B7QyYE4OBTzS7u3CrtmfYmAKriTLaL3xxtc aO4ah7Q0SVbjB1B5d9Bz8EVaXYdM4u3iNfETATI0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Ondrej Mosnacek Subject: [PATCH 5.12 066/296] serial: core: fix suspicious security_locked_down() call Date: Mon, 31 May 2021 15:12:01 +0200 Message-Id: <20210531130706.052916816@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ondrej Mosnacek commit 5e722b217ad3cf41f5504db80a68062df82b5242 upstream. 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 59438b46471a ("security,lockdown,selinux: implement SELinux lockdown") for how SELinux implements this hook. Fixes: 794edf30ee6c ("lockdown: Lock down TIOCSSERIAL") Acked-by: Kees Cook Signed-off-by: Ondrej Mosnacek Cc: stable Link: https://lore.kernel.org/r/20210507115719.140799-1-omosnace@redhat.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/serial_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -865,9 +865,11 @@ static int uart_set_info(struct tty_stru goto check_and_exit; } - retval = security_locked_down(LOCKDOWN_TIOCSSERIAL); - if (retval && (change_irq || change_port)) - goto exit; + if (change_irq || change_port) { + retval = security_locked_down(LOCKDOWN_TIOCSSERIAL); + if (retval) + goto exit; + } /* * Ask the low level driver to verify the settings.