Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1294199imu; Wed, 16 Jan 2019 16:35:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN6AW/OfbQBfe8DrH4hPjIKmOJ0d5nSu369rCOOqgTV0gTeQws7qSDIrdUvlu9qCnzgV5LL7 X-Received: by 2002:a63:7154:: with SMTP id b20mr11442712pgn.342.1547685339842; Wed, 16 Jan 2019 16:35:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685339; cv=none; d=google.com; s=arc-20160816; b=PPngXldSeGjONpO2G/Xs3ibWwu7PNC91nRkgKJ3K53Rr7p471LpnpPwPNj0UaHvTQj kXVLJC907pQl/dk7ae3FJzqDw/vMBHLHSEoZ96oKitTsalVkSnsthCqKNuzdm8YB9l1I +6ZxwgNKhl5rk9W336Fz64hjLFek5MeMFA7EVSV/XlFBZEC4oMTF/k3RXrXKHLTK2F8i OYzWrxYuRLpu9UlFZcOUrjhxLa82NRxi3V7lHcP9LSOYm1rHIZh1w5Xll3GIQ5o2z95V DFcvgFLbypPUOkAMOE0M9zhLtXMjThvSxHW6eNVh++mOhRAA5CjIEq8HlZfPvz9ZfSx/ 8nBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=VPr9EE+gtuF9KaPHPKsp6zW782gbtxgvmqhdui+yinI=; b=zMR2DnaKvwzv/0bzBfoCahw2DdAgFtFOD600HgzkbhzmdaRLeG0KmIPrCXXV9GGUbo +VtZumBCfTM2k8GSNoAXkFsHciBXnG6DhUcYvNhToj5ZO9HjIALSbIMW3wn23BFDyoha eKTbTqyssxiqohxfZl9bdqugJELxd65DmOR2CrcWy5kGUoLh+74HBIpnkD1zXix9vLZY +qM33hfYdWEhvhxaVHfaSEmyxiuS17Mp0v260tgjcHUTE06ZmVZwL2eEdmzo9v0IHbkh w6xopYeiUmWSs8ZdS16ZdBy5IoLCe8rrhokP9ai/V6MMWQoa7kZzY3bNWs4knzmm5+i5 8D5w== ARC-Authentication-Results: i=1; mx.google.com; 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 h68si2878346plb.375.2019.01.16.16.35.21; Wed, 16 Jan 2019 16:35:39 -0800 (PST) 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; 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 S1731974AbfAPUCz (ORCPT + 99 others); Wed, 16 Jan 2019 15:02:55 -0500 Received: from namei.org ([65.99.196.166]:56348 "EHLO namei.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731443AbfAPUCz (ORCPT ); Wed, 16 Jan 2019 15:02:55 -0500 Received: from localhost (localhost [127.0.0.1]) by namei.org (8.14.4/8.14.4) with ESMTP id x0GK2YN8003283; Wed, 16 Jan 2019 20:02:34 GMT Date: Thu, 17 Jan 2019 07:02:34 +1100 (AEDT) From: James Morris To: Kees Cook cc: Oleg Nesterov , Tetsuo Handa , "Serge E. Hallyn" , LKML , linux-security-module , syzbot , syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] Yama: Check for pid death before checking ancestry In-Reply-To: <20190116183109.GA21722@beast> Message-ID: References: <20190116183109.GA21722@beast> User-Agent: Alpine 2.21 (LRH 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Jan 2019, Kees Cook wrote: > It's possible that a pid has died before we take the rcu lock, in which > case we can't walk the ancestry list as it may be detached. Instead, check > for death first before doing the walk. > > Reported-by: syzbot+a9ac39bf55329e206219@syzkaller.appspotmail.com > Fixes: 2d514487faf1 ("security: Yama LSM") > Cc: stable@vger.kernel.org > Suggested-by: Oleg Nesterov > Signed-off-by: Kees Cook > --- > James, can you please send this to Linus in your -fixes tree? Done. > --- > security/yama/yama_lsm.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c > index ffda91a4a1aa..02514fe558b4 100644 > --- a/security/yama/yama_lsm.c > +++ b/security/yama/yama_lsm.c > @@ -368,7 +368,9 @@ static int yama_ptrace_access_check(struct task_struct *child, > break; > case YAMA_SCOPE_RELATIONAL: > rcu_read_lock(); > - if (!task_is_descendant(current, child) && > + if (!pid_alive(child)) > + rc = -EPERM; > + if (!rc && !task_is_descendant(current, child) && > !ptracer_exception_found(current, child) && > !ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE)) > rc = -EPERM; > -- James Morris