Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3392143ybp; Sun, 6 Oct 2019 10:56:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZPobxyxAX9CS2jqxCJEWIy66nqxHK1bmsqKwEWM+44Gs3v9CtU1/rFjxqj1yq+i2K++R7 X-Received: by 2002:a17:906:2a86:: with SMTP id l6mr7841063eje.120.1570384561768; Sun, 06 Oct 2019 10:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384561; cv=none; d=google.com; s=arc-20160816; b=PW3+oktxqWB76z56zG858sBtMR38y9mn3x/vVp0E3eR5/giITMf54e26WU5wy7vNk9 HCpAAb4SQg4454E6CLnyc3gEJP6FhBJfybAvyO05GIuTtUiQ17GEo88z7UodVUa1Tl1A gvmwNe8BSlQ5B8LAqn65S65ezBZ5nlsHJM+OJ8lTecFy7i/I43UM/bPZ3RueWdzUrPAG cY2/Spy/Gs9AVYuLFnSqMj6GXGFqdIDcpeToDRg5H1cqEfjJGUq9bfXrREt5jBV7xwFQ FjCx5dZe9cXmRStlVZoFdaxBru5K5Sqh1vKjPyaqXglNp2WpOUHWBRoGHOwr3AFmmIII 23nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Jz9M0U/Xpfz234SA0/vW5f374SPBmGW1IsUEBhvUA1E=; b=sxd+cFTWakXqFTqbwEPe2jJOgZMlNpQzeGfMFggvMwSpNxStrGxO19gwRoU4TW8huL AgrkDpPjLFEFul/VKE3IH25K8MIzGFHT0RZhBD7KmGlGCgYqLytan7cdWA94GlHiWJ29 31/SmB/rpR1kySWVJe3T6Wxv8LX+n3ffWKP/YlaAYg89C9FeSdfKsZ8uMmy4FU6HdN+3 YMsOinK5ynX3KA6Tk/t8A/3bTOQW7usYoqozhb1CjImMhnDqpd1v79ES1JDPL1yL2jSE Fe5Vu7wcHQ+yU2JIUVZrTsZil6Eo8jX27QlZWLw3974QWL6gEtfuv7L4qqv4ZX7HmReb HPHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IoysWNZh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l18si5751245ejg.248.2019.10.06.10.55.38; Sun, 06 Oct 2019 10:56:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IoysWNZh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730051AbfJFRzT (ORCPT + 99 others); Sun, 6 Oct 2019 13:55:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:51352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728359AbfJFRy3 (ORCPT ); Sun, 6 Oct 2019 13:54:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3A9422459; Sun, 6 Oct 2019 17:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383960; bh=tQiSvNVTkjv8Ne/BbocQ9GxSGV/1O9mRi+mOMl8LBM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IoysWNZhRF4xeeTVy0QMREhX0WUqU4w7gP8JgiXkaeBoeGTWIpntUW/nYX0+/lsZH KmNLOPHbKtcP7GtmsS0TLe6scUnwqmOyZ+AsBJt5aS5idCNL9ZNmLKg73xYevZLNc8 QC555pdytUOszLc4ZRWUyjYmHPUXfK+L7K8Y9nGQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Casey Schaufler Subject: [PATCH 5.3 158/166] Smack: Dont ignore other bprm->unsafe flags if LSM_UNSAFE_PTRACE is set Date: Sun, 6 Oct 2019 19:22:04 +0200 Message-Id: <20191006171226.169743782@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jann Horn commit 3675f052b43ba51b99b85b073c7070e083f3e6fb upstream. There is a logic bug in the current smack_bprm_set_creds(): If LSM_UNSAFE_PTRACE is set, but the ptrace state is deemed to be acceptable (e.g. because the ptracer detached in the meantime), the other ->unsafe flags aren't checked. As far as I can tell, this means that something like the following could work (but I haven't tested it): - task A: create task B with fork() - task B: set NO_NEW_PRIVS - task B: install a seccomp filter that makes open() return 0 under some conditions - task B: replace fd 0 with a malicious library - task A: attach to task B with PTRACE_ATTACH - task B: execve() a file with an SMACK64EXEC extended attribute - task A: while task B is still in the middle of execve(), exit (which destroys the ptrace relationship) Make sure that if any flags other than LSM_UNSAFE_PTRACE are set in bprm->unsafe, we reject the execve(). Cc: stable@vger.kernel.org Fixes: 5663884caab1 ("Smack: unify all ptrace accesses in the smack") Signed-off-by: Jann Horn Signed-off-by: Casey Schaufler Signed-off-by: Greg Kroah-Hartman --- security/smack/smack_lsm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -937,7 +937,8 @@ static int smack_bprm_set_creds(struct l if (rc != 0) return rc; - } else if (bprm->unsafe) + } + if (bprm->unsafe & ~LSM_UNSAFE_PTRACE) return -EPERM; bsp->smk_task = isp->smk_task;