Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2690454pxj; Mon, 31 May 2021 08:20:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKY/ncXX7VnOivR3qkNEFoKV+uSQQaV0+1QLARwQ23ly5a0i+76IwenXeUI3tnq6JknUxC X-Received: by 2002:a05:6402:344:: with SMTP id r4mr7752037edw.226.1622474412125; Mon, 31 May 2021 08:20:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622474412; cv=none; d=google.com; s=arc-20160816; b=Sp+RQpe/2EhphAZtS1MsT7KtyRBbYEVZMdtQyupE/4+CFfs54SEtSpPGzFTUyc++U/ 2VnGxzfKQPo/0aGLbfIkaOyxONFf8gi/hQEtq0FDRVDKoQI8FFBbjzu4a5kJe+GLc7uU jFIVwGW53pkpmkbOV6Ea+ckDLoovRp2pLw6oVOxxoBKDUCBRLxEZQaQcDYUIaS1TDmcL yavw9VRggUOiCr2HPgISV2WYBDv90gPu+nmgtezMnLg5ueiYpLmejlRJysFI6bLjJHcl nQPr172YB0GoNow025gO5D8zOQX46QIFQAp7Ct3EezpaX621/saWO6/wLHMCeobh6fLY 1qBg== 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=fjSZYq4U/b3zy2A9bVxKLlMaXoTqKiysfaimrATaMPE=; b=ejlUGnFd+AzQxujwK3Eit+FFCjnGPdz9L53jzGdMPvXbzyJHGJayIMRxX85uxNi0Yn jx7K/LwD5EaVts6ZZa048o/SXk+vipAQexeDa1YyoRI9y9xfewE35Ptfs8Pz8cCJiNVl SOi0gzx7OTkAi2ElJobeX5DPaoKrnoL05KjSMCoNmre0SsmJtVsmiuFndgt49/F9q/fJ DW5NLJ0AdLKNLJwgQW553+7FUMWT/Ok3Gq63ewnUU1zq2ZoZynLvv5Yl8YWmYfztcA/5 U9Xt6iXsk4r2+z3vfiI/7OI6gcFJRqKXpyTICzLLbnFa1AYNdrQiMjv5scmQAEXaHEi6 OBqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="S1A/5vIm"; 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 k1si8573581ejg.69.2021.05.31.08.19.49; Mon, 31 May 2021 08:20:12 -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="S1A/5vIm"; 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 S232144AbhEaPUa (ORCPT + 99 others); Mon, 31 May 2021 11:20:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:43228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233763AbhEaOPf (ORCPT ); Mon, 31 May 2021 10:15:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 70FC6619A3; Mon, 31 May 2021 13:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468569; bh=GK9mZAHadxSgipiVX8nZwVm6mN0rxfxek95PioM9FE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S1A/5vImeNVeWOSkn9ECnaZoP5eL7cbxLw18DqotVQxSup3bb8QRT+uhW3sYgAjV2 D2Lz8vZraOC7BfX0vT6mnQdp/MKn53cOIhCqrcprBmWhFFLtGOa1HXJIfupLqWU48I MOpDsWTU8vcI5Ysm3AaHgMlDUmgYyxPWZMNMqXqQ= 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.4 039/177] serial: core: fix suspicious security_locked_down() call Date: Mon, 31 May 2021 15:13:16 +0200 Message-Id: <20210531130649.281904156@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 @@ -863,9 +863,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.