Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3376401ybp; Sun, 6 Oct 2019 10:34:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeo6K/IJnP/WvT5gJ+fHcutUEwlpX0LMEkm3dDwb8fqOASTKV2pphVhHyuOt/sMiHiKRRc X-Received: by 2002:a05:6402:2022:: with SMTP id ay2mr25526460edb.109.1570383269433; Sun, 06 Oct 2019 10:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383269; cv=none; d=google.com; s=arc-20160816; b=0LNEgsz6e9pYOyN9JdwJJjIFGpHeSZMpz+PsXkJnWuovX3N9VbmjGy44Lf2YF/2C+4 C1se4i5IMo/57V62bO08ftXhUQ6lSIsqGk8OAEKI9+HF15mteUEQ3qq0g7zpiAVgJayr Y01g51skdwNuSJZvSlXXy0kBxQX3XlANw0P2Vf4YYWZWLTgnEyoM1Vhia0KVdI1xfIAP Sf9jcXQAPX7i/X5LfdaeBgmWDGJRqWNaCHZ1kLb+G6z9HAMpFFOU4n00B93PNHS3EAzn Kn2L3Zjt9c80+7JxGPnPNImBPfysHounE99eH6mBwn3D5HVKKGYP5YcNFCbRvFyDdKfi R3QA== 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=6K/Kl6FhwNGM7Qhjsc+W6Ucxr4HMDGMXOjVEr4kaoXs=; b=o0gZH3E50Ps2hZ5I7zEFtiocaSL8VmzRnQ7KbuWxWLnKy7k8w/CYkdESIW3vHKOKq0 W+PRLHmud36bSQmmb/5NptNgaIaAYPGnssbnbeOFGunjRLyBuZoE5rLVj+/LXjo3oY9G 2qulyVW5tBb8Km1xRQLMuDLxRsLWp2L4q684OB9kqmLzC7LRmDfmJue150TmdPYnCz8i Wij3pq15eyrycFrYl3/5V3OY0qQFBn5Vg65gbpgaa7++07XLmXoYT1lPMjmhobJdthnT GvCLOtMvMNuBA2RmvKu2Kb2C8112z40ch3m3SxEzdmuT2PulTI+GV80zcqgW+rbT7RCm IBBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UzMuSkyD; 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 x8si7897057edd.282.2019.10.06.10.34.05; Sun, 06 Oct 2019 10:34:29 -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=UzMuSkyD; 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 S1729569AbfJFRcZ (ORCPT + 99 others); Sun, 6 Oct 2019 13:32:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:58876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729557AbfJFRcY (ORCPT ); Sun, 6 Oct 2019 13:32:24 -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 22C822133F; Sun, 6 Oct 2019 17:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383143; bh=fjJrdjq9ByRxGdjY6wKrvDvBEtcNvBtzbjBhKXMgaT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UzMuSkyD+PMAWEA7YppHXXThhuWfkFyXh+920M3jWGLioyfD5alQmpRge4i+BnnmI I0kpifbFPoDek2A4LQEOVQx9g6KdgS8KE1TfIyPEqB0ftgKLXqpT2LC4nnlQthjrm6 KbgqopKPS/UOPdxckewjC4TWXWcKtTvVmLr5TOuU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Casey Schaufler Subject: [PATCH 4.19 102/106] Smack: Dont ignore other bprm->unsafe flags if LSM_UNSAFE_PTRACE is set Date: Sun, 6 Oct 2019 19:21:48 +0200 Message-Id: <20191006171204.088611292@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@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 @@ -947,7 +947,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;