From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932674AbdKAIFz (ORCPT ); Wed, 1 Nov 2017 04:05:55 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:47191 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbdKAIFr (ORCPT ); Wed, 1 Nov 2017 04:05:47 -0400 X-Google-Smtp-Source: ABhQp+QeDNbCdAiQ1sMG3qROHTNOZ/SGuVNuS03AVohhHGa8Rh+64EA45xLzv+q2RwMErngn11Cz1A== Date: Wed, 1 Nov 2017 09:05:42 +0100 From: Ingo Molnar To: Thomas Gleixner Cc: dvyukov@google.com, hpa@zytor.com, linux-kernel@vger.kernel.org, bot+2af19c9e1ffe4d4ee1d16c56ae7580feaee75765@syzkaller.appspotmail.com, torvalds@linux-foundation.org, peterz@infradead.org, gratian.crisan@ni.com, linux-tip-commits@vger.kernel.org Subject: Re: [tip:core/urgent] futex: Fix more put_pi_state() vs. exit_pi_state_list() races Message-ID: <20171101080542.c2yugwpeiy3jpfc7@gmail.com> References: <20171031101853.xpfh72y643kdfhjs@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Thomas Gleixner wrote: > On Tue, 31 Oct 2017, tip-bot for Peter Zijlstra wrote: > > Commit-ID: d5f6ac33189af48a0dc011190af5144947a30a76 > > Gitweb: https://git.kernel.org/tip/d5f6ac33189af48a0dc011190af5144947a30a76 > > Author: Peter Zijlstra > > AuthorDate: Tue, 31 Oct 2017 11:18:53 +0100 > > Committer: Ingo Molnar > > CommitDate: Tue, 31 Oct 2017 11:54:52 +0100 > > > > futex: Fix more put_pi_state() vs. exit_pi_state_list() races > > > > Dmitry (through syzbot) reported being able to trigger the WARN in > > get_pi_state() and a use-after-free on: > > > > raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); > > > > Both are due to this race: > > > > exit_pi_state_list() put_pi_state() > > > > lock(&curr->pi_lock) > > while() { > > pi_state = list_first_entry(head); > > hb = hash_futex(&pi_state->key); > > unlock(&curr->pi_lock); > > > > dec_and_test(&pi_state->refcount); > > > > lock(&hb->lock) > > lock(&pi_state->pi_mutex.wait_lock) // uaf if pi_state free'd > > lock(&curr->pi_lock); > > > > .... > > > > unlock(&curr->pi_lock); > > get_pi_state(); // WARN; refcount==0 > > > > The problem is we take the reference count too late, and don't allow it > > being 0. Fix it by using inc_not_zero() and simply retrying the loop > > when we fail to get a refcount. In that case put_pi_state() should > > remove the entry from the list. > > > > Reported-by: Dmitry Vyukov > > Signed-off-by: Peter Zijlstra (Intel) > > Cc: Gratian Crisan > > Cc: Linus Torvalds > > Cc: Peter Zijlstra > > Cc: Thomas Gleixner > > Cc: dvhart@infradead.org > > Cc: syzbot > > Cc: syzkaller-bugs@googlegroups.com > > Fixes: c74aef2d06a9 ("futex: Fix pi_state->owner serialization") > > Link: http://lkml.kernel.org/r/20171031101853.xpfh72y643kdfhjs@hirez.programming.kicks-ass.net > > Signed-off-by: Ingo Molnar > > That lacks a stable tag. > > Other than that a late: > > Reviewed-by: Thomas Gleixner Ok, I've amended the commit with these two changes. Thanks, Ingo