Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp660958pxu; Fri, 4 Dec 2020 12:13:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvG8xAv/8NFXKJaws/G/KWzTNYfgrd390nwoe+T63QmTdcPe/OfGGi4Lf3rqJ6Y1EuehCZ X-Received: by 2002:aa7:c3c2:: with SMTP id l2mr9133745edr.15.1607112834899; Fri, 04 Dec 2020 12:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607112834; cv=none; d=google.com; s=arc-20160816; b=SQ7xRait7HWRSaYmuVbdRoquAY0JTUqcWm7Dli7ZIc/K1iDPautXupIvy4iAuy+986 u6Ixxob2R8F2c7XwSKuBgEfGpckdqCByQ/EaIP2loU4k7ke9r3ul92r9BtBfvBygoRvV jsfYxgBelp8LEV7DQehdcqare+ARHU9NOqrpIPhJUuE+ByEAf/xef+0Ub8+3ZPJtLJb6 qt1H9ScbKkrv5Opq6bpaAhbuPfNnN4lZNa70EZDevzL0eh2W1mV3VAd5TQL+v26YW6jd wbhJjaobP/eMDFArd0stcdh0RujeowztG0l0THXtTzCAkC9oKNwkWCRjg1dlbQfz3HJR XTOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zQpn0o892pEbZLHFd+9gLpvB3MBMiU/L0nR9Ji5w5Ws=; b=dlaWZCLjnrRo/F5BPk8Iq8xCfKOWfCiciox95ZQqWamOPqtM8d+j6gGlcg+HHvMhP1 GmNcafBt4M56ViKGm+esb7nNovbXTsfhPApfanZ5wkDVeENdHq032Za+m4H1f1ypExem ax+NxC3sV9ZQO2KoI7hnQxDNDqqvMI3aHQwAA13lVUwp/IxOyDjzzi4B6Ye/9LUEPbUH fMRyP34mx4ogIpbzT+vZw3EsTkcgqupAbuptBFB/8w7j673vxOR42wEs/mMo8WYhSUE+ lsAiMig29Vou+BQZBd6WNI1D6jtq/rKWpRvm0uAFEwhmgXEqtQ38nIwrQyJpokDfxG2P GVxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=EIFCJEvQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p26si3641573edw.396.2020.12.04.12.13.31; Fri, 04 Dec 2020 12:13:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=EIFCJEvQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729972AbgLDUMA (ORCPT + 99 others); Fri, 4 Dec 2020 15:12:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727693AbgLDUL7 (ORCPT ); Fri, 4 Dec 2020 15:11:59 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C021C0613D1 for ; Fri, 4 Dec 2020 12:11:19 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id a9so9372183lfh.2 for ; Fri, 04 Dec 2020 12:11:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zQpn0o892pEbZLHFd+9gLpvB3MBMiU/L0nR9Ji5w5Ws=; b=EIFCJEvQUYJnBphqSUS2irvQEUigMurEkzX40ERNG5CNdR9rcGCkWuwqRaK1dES97D 3lg+hjnOypTh+xGzaIcHQnM2LINwLeuxZ+zvYpW2GPOcwVGEq6Sp5DleHqcutwEEDY3M 66uvPwJsErHJ6BO5lKDWbDNY3QeHtwpfioKGk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zQpn0o892pEbZLHFd+9gLpvB3MBMiU/L0nR9Ji5w5Ws=; b=meALmhHCHLN1TH6Q1z0ro16WM/x0eWEFFRJiaM94Xe1L8gSVVcb1Iy2L5yGakQb2x1 bRrjcTDQZJpjgrWTBGVprS16cBorOxPzSML6xD4+HKztE8OS4nAfaWcd50MHiYxlUp3L 7aWta9DPZwlroAEg1v2aEaog/wBXmtT+4yjM+5GrgVA+On7RqLCpcbHFxi734qO8cws/ uDoFHXeNuoICdp+kWJ5dGDZTN8iLCLfQ2HnUNHfxMCH42Roy/p8vUlC8vMrx0dn1Rwt6 APNXv3WYJzQ9yIZKvC/O/ZA5nlTy16IzxERnrEPPVXJj9Im4L9KJVk/NxQCy7og2DF4x 9MCQ== X-Gm-Message-State: AOAM533O1Ab8qI8ae7ItKCLC1ub+2FlZfR6M9hszIk6uZALuRNOHLFmD Lj9C+L1GTWvcLDEjyENrRoXXcWgCPQumtg== X-Received: by 2002:a19:c0c:: with SMTP id 12mr3985757lfm.315.1607112677287; Fri, 04 Dec 2020 12:11:17 -0800 (PST) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com. [209.85.208.176]) by smtp.gmail.com with ESMTPSA id w11sm2010545lfl.33.2020.12.04.12.11.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2020 12:11:15 -0800 (PST) Received: by mail-lj1-f176.google.com with SMTP id q8so7927251ljc.12 for ; Fri, 04 Dec 2020 12:11:14 -0800 (PST) X-Received: by 2002:a2e:9bd2:: with SMTP id w18mr4078394ljj.312.1607112674455; Fri, 04 Dec 2020 12:11:14 -0800 (PST) MIME-Version: 1.0 References: <87tut2bqik.fsf@x220.int.ebiederm.org> <87ft4mbqen.fsf@x220.int.ebiederm.org> <875z5h4b7a.fsf@x220.int.ebiederm.org> In-Reply-To: <875z5h4b7a.fsf@x220.int.ebiederm.org> From: Linus Torvalds Date: Fri, 4 Dec 2020 12:10:58 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/3] exec: Transform exec_update_mutex into a rw_semaphore To: "Eric W. Biederman" Cc: Bernd Edlinger , Linux Kernel Mailing List , Peter Zijlstra , Ingo Molnar , Will Deacon , Jann Horn , Vasiliy Kulikov , Al Viro , Oleg Nesterov , Cyrill Gorcunov , Sargun Dhillon , Christian Brauner , Arnd Bergmann , Arnaldo Carvalho de Melo , Waiman Long , Davidlohr Bueso Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 4, 2020 at 11:35 AM Eric W. Biederman wrote: > > From a deadlock perspective the change is strictly better than what we > have today. The readers will no longer block on each other. No, agreed, it's better regardless. > For the specific case that syzbot reported it is readers who were > blocking on each other so that specific case if fixed. So the thing is, a reader can still block another reader if a writer comes in between them. Which is why I was thinking that the same deadlock could happen if somebody does an execve at just the right point. > On the write side of exec_update_lock we have: > > cred_guard_mutex -> exec_update_lock > > Which means that to get an ABBA deadlock cred_guard_mutex would need to > be involved No, see above: you can get a deadlock with - first reader gets exec_update_lock - writer on exec_update_lock blocks on first reader (this is exec) - second reader of exec_update_lock now blocks on the writer. So if that second reader holds something that the first one wants to get (or is the same thread as the first one), you have a deadlock: the first reader will never make any progress, will never release the lock, and the writer will never get it, and the second reader will forever wait for the writer that is ahead of it in the queue. cred_guard_mutex is immaterial, it's not involved in the deadlock. Yes, the writer holds it, but it's not relevant for anything else. And that deadlock looks very much like what syzcaller detected, in exactly that scenario: Chain exists of: &sig->exec_update_mutex --> sb_writers#4 --> &p->lock Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&p->lock); lock(sb_writers#4); lock(&p->lock); lock(&sig->exec_update_mutex); *** DEADLOCK *** No? The only thing that is missing is that writer that causes the exec_update_mutex readers to block each other - exactly like they did when it was a mutex. But I may be missing something entirely obvious that keeps this from happening. Linus