Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp284160pxj; Fri, 7 May 2021 08:32:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJfk7g2FCwVXgyzjC+siIpg5dHrD9ElsbGC0FL8aKlqXwls5XlqATA62uo2pcZJDRTVlkX X-Received: by 2002:a17:902:56d:b029:ee:9129:e5e8 with SMTP id 100-20020a170902056db02900ee9129e5e8mr10403490plf.70.1620401540636; Fri, 07 May 2021 08:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620401540; cv=none; d=google.com; s=arc-20160816; b=DhzIfaXLktr1tJmgR8045QRmHPL3Z5zePk+UKSclbSSfVzmI+b8T8yrpgwv+I/QGwH aXxyn22jBjJUqY+VkuoaylGRJ/sidJWpvKdh+0i+/kreiOnmXF2RdEu5rR8BFSe2CZzE awr0qtQxrWRVw/jd26c4o1ov2iTsm6oHPzsloGV4GqHi2VRtGV3w7Ch9YmNxhgnTuUsH bkM7Hob3Z6zHEWm911p0sA9N7XeOqXb9CLUzSpPHpbLA9xAL2ctVu3Nw/ayxK6qWaMrX ynXv1k0JyBQ03A4TjHMQepBQxc0Nc8XS2KnD2+o6UHIyfSWPRPzGdrL2brhUFqzbmhfk wK7Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=YXvAn6PhmCpGYLW0QYPpJQEW72/FRvqimCSflbY0beM=; b=UXDiGQciG+CCqV5h5FbhokltZcZR54MtKH9WvEbH7qX50QYSlRA5h9YiU1lf/rZClL 67/RYjA6ar5OxKktUcdvzM2xgbl8eQVKBzDsy6a6Ctc0MdjeuUfNfqsoumtqhcTr/Mt6 HSHOCTgf5J066o1yRUNbUzqtV4pTYPXCKb/WySLD4Ci2qluFYce5qTN57Gx8h6OvsfRU zQtBG2HIcvleFTOqeTaRcIiNGvkSWMWc5WexW91ar1T+ySQfWiOULCQKtBUFv1IgpWSJ tlPBno9SsB+xtpLjchN/OqtKmuOBKKwQOwALyL9NHCWnHcX8AzlM2jr8ff428TfN7hva s6PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W/16OV3y"; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si7413211plg.400.2021.05.07.08.32.04; Fri, 07 May 2021 08:32:20 -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=@redhat.com header.s=mimecast20190719 header.b="W/16OV3y"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235662AbhEGL63 (ORCPT + 99 others); Fri, 7 May 2021 07:58:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22977 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235649AbhEGL62 (ORCPT ); Fri, 7 May 2021 07:58:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620388648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YXvAn6PhmCpGYLW0QYPpJQEW72/FRvqimCSflbY0beM=; b=W/16OV3yg7UORul4Twuit0hF+ptIIBKPe1zhwJKk6K3QsnTXsmvrvf9/1XF3mIFl5VEHus 7rciNw3NmdyF++vE09PvKhCDs3yQQ/OQPOOeHJLU8FlT5+xa1Vy5VUsKAoxkrOMcA7iGKi EifHeqMWIGXnNpWLci4SE9RYCWjGMh0= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-543-zhmweGRaO8CK5HHIgduirQ-1; Fri, 07 May 2021 07:57:25 -0400 X-MC-Unique: zhmweGRaO8CK5HHIgduirQ-1 Received: by mail-ej1-f69.google.com with SMTP id ne22-20020a1709077b96b02903803a047edeso2902434ejc.3 for ; Fri, 07 May 2021 04:57:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YXvAn6PhmCpGYLW0QYPpJQEW72/FRvqimCSflbY0beM=; b=COAc9birN2l8tOPgzJMOuScj5wIRgajsmzP5mFMpPW54waXPmEOqpIJobCESg8uZlJ 3fLyI+Gj229UI+dsdDgPAlQHDIEoWzwNzH76rcDIaT/QwIyosASVQdU1zciT1E8htgdG WMaNQ+H/3hq+Ug18LrUvKPc/SnwxXBflhtlXTfaUMENDpJFXE7VKZVAALcpF1aQiGble cNTKOCtwtEk3qs6T1iimVVxnUP89DUd7r68wp3KuAW66QIFnVwhtfHdvfLkWCSzw/wk2 3S86PCX0W+wOJMbuihNRLNb6WN0iCO/ONg/FyIOARHklV4s/iTSJQtH2A4NYulyYmRud qUsg== X-Gm-Message-State: AOAM5301Gc0Xa0lBWtpJThnZbaAK4twm+WDQWS10rZzu85sU4inFlQdW ZpxG2rA37XFVWjuv35iF9CclGthkF7S1ySdBgvEWe13IGiTzSi8GQxJ7Swa5TLQS/vMeo+B23pA hdnPyZPdKgvOnMWtqDbGRI6nk X-Received: by 2002:a05:6402:518f:: with SMTP id q15mr10961513edd.345.1620388644407; Fri, 07 May 2021 04:57:24 -0700 (PDT) X-Received: by 2002:a05:6402:518f:: with SMTP id q15mr10961502edd.345.1620388644218; Fri, 07 May 2021 04:57:24 -0700 (PDT) Received: from localhost.localdomain ([2a02:8308:b105:dd00:277b:6436:24db:9466]) by smtp.gmail.com with ESMTPSA id l7sm3657324ejk.115.2021.05.07.04.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 04:57:23 -0700 (PDT) From: Ondrej Mosnacek To: Greg Kroah-Hartman , linux-serial@vger.kernel.org Cc: David Howells , Matthew Garrett , Kees Cook , Jiri Slaby , selinux@vger.kernel.org, linux-security-module@vger.kernel.org, James Morris , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] serial: core: fix suspicious security_locked_down() call Date: Fri, 7 May 2021 13:57:19 +0200 Message-Id: <20210507115719.140799-1-omosnace@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Ondrej Mosnacek --- drivers/tty/serial/serial_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index ba31e97d3d96..d7d8e7dbda60 100644 --- 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_struct *tty, struct tty_port *port, 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. -- 2.31.1