Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2870636pxj; Mon, 10 May 2021 12:38:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1fTEH8lZ6+7gyStLFkxmCGGpjzNeoZ4ouk9L7K+OPoAGhtEoOzO/nWBsRPZv/IqwqBJ5s X-Received: by 2002:a5e:8a08:: with SMTP id d8mr19706848iok.192.1620675526413; Mon, 10 May 2021 12:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620675526; cv=none; d=google.com; s=arc-20160816; b=Wqx9zW/927mPjT3fQb3z/PAg841S3mq+qKizhl66rbUvjjEWCpbZaR3bCZ5eNh16Ns NY0GLyc3aHzGTifTT9L4LoySrVlv+YDwO3JteBKW1gUEWxHCJCDtAVIme9F3cb6KLjRH 8nnaBUhZUmsLoVOgfWuVdf5+iaea+NRSkqgFegRcq7yjZl3bkVC8aMbQUdcHfkh7VEQq cx4vvYRhLWfCW5JTZ8sc2E939jOrWKB/eT4GHQNTVPLTlenvwqr2M3Sglt/9HhS7J0NT EdSATA5x2oSM3OfeTLHym9MSSnv280Nc+02q8EC+LjGEKGyAWU2uuY9oubJiUah2XWyY GJ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=w733lNx5OPvObGbQFjQ0hyLyLp32Sr7cenOR1wA1DIY=; b=UslKHRfuIJG1oA40jXwZvsG3rT4uUEG3rT+uiqETHRhuP+6dRc+iyyW4cbiWYCPACO EuqZTpeVBjk11EsgoIqsCdZJRfX5NyWCWVEtixExdnnuGOlhy3CvpFQI8yyZhpkthKXb UMNZzRuVE/qwCJPrq9pchnikmYk6AhNCofMmlmloEK4K8FtQYBxQG+17wPMM0blzY7vX 98WKw5XZtkJEsDtk8qEu/S3NF1O9cGQ+xubGQjDFSt0eudxpzpBDJsYzzFk2YqXQ6wd2 Xvy1zmUV5eMrSZl/rooWPC1Oo7HFg3Wxf51Xz+BcXvicoeQhcWoO6vs4CckAu1kbvBUp eLIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lVGfbvll; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si16163193ior.61.2021.05.10.12.38.33; Mon, 10 May 2021 12:38:46 -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=@chromium.org header.s=google header.b=lVGfbvll; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231808AbhEJTiF (ORCPT + 99 others); Mon, 10 May 2021 15:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbhEJTiF (ORCPT ); Mon, 10 May 2021 15:38:05 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16B0FC061574 for ; Mon, 10 May 2021 12:37:00 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id m124so14020186pgm.13 for ; Mon, 10 May 2021 12:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=w733lNx5OPvObGbQFjQ0hyLyLp32Sr7cenOR1wA1DIY=; b=lVGfbvll40bgW3gA0fIk8JnjEglkVV5jCVUhsmj7ENwfKb7AnT261Kn/TUZHgnA8iQ vFA72QWJlBYZTSrbMdmrm1kqYiHWzkPRKp2KbV392cJ+EqzkEt8SkIGerLo/bRjyzH+2 UrG5K2+KQ2ObPy4UieTwNbPSU/s9lxlr/kz7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=w733lNx5OPvObGbQFjQ0hyLyLp32Sr7cenOR1wA1DIY=; b=Xu3IMaxguDWSAuxEJvXX5Ehxp3Wx06PJKexK0xFzE+EwzUMA6M5vQ34BRg2GZWJYp2 d030zdOsQQslUUa/j70HfAmWALoG46TdyCsv1YaUkczZ0FlNUEX6uVL1xjY2MsDkGCia lnMx3hXgAVajTGSQKwq6440IUjiyIcmGFjolRWddnmW2vu/WrN5RiAsvLY+nnbcA1Tmp Np9popwICsiIkRTCMl6H0lZkzs41uNrw9kjhOW04DiS/x+8HhtPRlPFZmK6dvA3VnN4I ZytbQo2Eshrfy4hbfWBu/4RsUO50Ioi5CsSD4geTLoFy0lcvyxe68tOeFeTo2Ds/MkrH hMow== X-Gm-Message-State: AOAM532WxTD5F3gtpkL7K066bIZeOs2D1EoarFCvI4FC8w+hzuWkMGfb HgNxNqp3t6MXL94tXYpOnHboHA== X-Received: by 2002:a63:1064:: with SMTP id 36mr27146092pgq.164.1620675419601; Mon, 10 May 2021 12:36:59 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g18sm11938600pfb.178.2021.05.10.12.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 12:36:58 -0700 (PDT) Date: Mon, 10 May 2021 12:36:56 -0700 From: Kees Cook To: Ondrej Mosnacek Cc: Greg Kroah-Hartman , linux-serial@vger.kernel.org, David Howells , Matthew Garrett , 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: Re: [PATCH] serial: core: fix suspicious security_locked_down() call Message-ID: <202105101226.E2AD9AEC@keescook> References: <20210507115719.140799-1-omosnace@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210507115719.140799-1-omosnace@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 07, 2021 at 01:57:19PM +0200, Ondrej Mosnacek wrote: > 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. Oops. Yeah, good catch -- I missed the kind of weird handling of retval in this function when I originally reviewed it. I think the goals of just covering IRQ/IO port changes originate from here: https://lore.kernel.org/lkml/26173.1479769852@warthog.procyon.org.uk/ And I think the "Reported-by: Greg KH" originates from here: https://lore.kernel.org/lkml/20161206071104.GA10292@kroah.com/ So, yes, I think your fix is correct. Acked-by: Kees Cook -- Kees Cook