Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759172AbcLRSc6 (ORCPT ); Sun, 18 Dec 2016 13:32:58 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34826 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753423AbcLRSc5 (ORCPT ); Sun, 18 Dec 2016 13:32:57 -0500 Subject: Re: ipc: BUG: sem_unlock unlocks non-locked lock To: Davidlohr Bueso , Dmitry Vyukov References: <20161218162838.GA24788@linux-80c1.suse> <20161218162952.GB24788@linux-80c1.suse> Cc: Andrew Morton , Ingo Molnar , Peter Zijlstra , fabf@skynet.be, kernel@kyup.com, LKML , syzkaller From: Manfred Spraul Message-ID: Date: Sun, 18 Dec 2016 19:32:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20161218162952.GB24788@linux-80c1.suse> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1318 Lines: 50 On 12/18/2016 05:29 PM, Davidlohr Bueso wrote: > On Sun, 18 Dec 2016, Bueso wrote: > >> On Fri, 16 Dec 2016, Dmitry Vyukov wrote: >> >>> [ BUG: bad unlock balance detected! ] >>> 4.9.0+ #89 Not tainted >> >> Thanks for the report, I can reproduce the issue as of (which I >> obviously >> should have tested with lockdep): >> >> 370b262c896 (ipc/sem: avoid idr tree lookup for interrupted semop) >> >> I need to think more about it this evening, but I believe the issue >> to be >> the potentially bogus locknum in the unlock path, as we are calling >> sem_lock >> without updating the variable. I'll send a patch after more testing. >> This >> fixes it for me: >> >> diff --git a/ipc/sem.c b/ipc/sem.c >> index e08b94851922..fba6139e7208 100644 >> --- a/ipc/sem.c >> +++ b/ipc/sem.c >> @@ -1977,7 +1977,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct >> sembuf __user *, tsops, >> } >> >> rcu_read_lock(); >> - sem_lock(sma, sops, nsops); >> + sem_lock(sma, sops, nsops); > > *sigh*, that would be: > locknum = sem_lock(sma, sops, nsops); Yes, I can confirm that this fixes the issue. Reproducing is simple: - task A: single semop semop(), sleeps - task B: multi semop semop(), sleeps - task A woken up by signal/timeout I'll send a patch. -- Manfred