Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2651212pxj; Mon, 31 May 2021 07:25:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrFaqP0iovgv2UCAVJWA/PntVDZi7NcqVmkyY3bplN6PtYIQYDMO0SxOhUnQYZ0IBXHYUV X-Received: by 2002:a6b:b214:: with SMTP id b20mr1049889iof.199.1622471102812; Mon, 31 May 2021 07:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471102; cv=none; d=google.com; s=arc-20160816; b=g3AdYYAi6/Tk/WxiY+YLYIBQ0pnJtXL4pXwXNFfnB4cP1Tm1bG1z7zwasjpXFSPpBg 6rU4byveJxi6Q8j8g5K6GYLwC7XAwIH//gx4ccJb5LTIAUswKnqovKYpIuLOvgBypRNu 7W+zss84tqHFshxQ7ge/L33MHqED+iEfj3b6Uwdk40glqH93RvfsEr1gNotw3FDonbik SqDxRaj/iw237QpCBe97/GtlXJF1v7iw7IFuJSvcRc4maAWZNODzjHduTIPCO9Fe934+ E/gIVOE4VQ8aI6/EhQ06DbJoGmhQCBA2zTMMPxl/l8y/jcXWf7AfRKSfqpGvskDuOBMe A8OA== 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=WoSiQY0RDr5nSsx/h4pGQPfASCyfhZg1QdIq/Kbm+zqTPncZkNpaqthds7b529EWTX tKz6o538kqE0bdWcr4m6GwBFxLIOy/gyobl26rcv+pxsDdAGXb8jMgxV53DHFTI18WTZ s0jqYnOngO7Co4YIhvVoo16lDQ2WiuZsI2WCI8sILtuhtapUW/jVRZ12rOEivwK1j9jX 29bUImkhbZ0aWLAiA/+j6X/YB9fz8xFB1EMXSmdm9jlBvAFdYSzpwpqvmvVz51KT1Hrq +uijn7hD7LTPnIaqWDkXwhpC1lXyp+3m6eJA/ijStW8/PFL4aqXWQCBv/C+SzmIwFUYn F0/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VC7FE5rY; 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 t2si10522586ilo.160.2021.05.31.07.24.49; Mon, 31 May 2021 07:25:02 -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=VC7FE5rY; 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 S232814AbhEaOYz (ORCPT + 99 others); Mon, 31 May 2021 10:24:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:56076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231691AbhEaNur (ORCPT ); Mon, 31 May 2021 09:50:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E6066162C; Mon, 31 May 2021 13:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467927; bh=Bzk3q18Rykvj7pc36KDsfBnTnyDHicERbODMBtkjrJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VC7FE5rYnxoTkAwNPEDi05gwapXsLUNEF5FxL0A8NPUrGBemHJ28EqBn4yXSfZ76x l/BqyePg3HEnNMg6ugGziKI/i4N1vOxgiCvGkccdWt5jJxIDwZRsc15K6GLaydw7LN s/4NPSMk0UuNhYZ8qpOdEtluB/bsx2JTli/ZfwMQ= 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.10 053/252] serial: core: fix suspicious security_locked_down() call Date: Mon, 31 May 2021 15:11:58 +0200 Message-Id: <20210531130659.786984803@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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.