Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3827523pxb; Mon, 21 Feb 2022 06:31:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLdHsUT7q0uxAi7M8fNxX6vOqrU5PCwA52MGW6CcU8/+X7P2r/6uR9XFBC91KraFJMk09a X-Received: by 2002:a17:903:1210:b0:14d:c2c0:cce6 with SMTP id l16-20020a170903121000b0014dc2c0cce6mr18924284plh.17.1645453899999; Mon, 21 Feb 2022 06:31:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645453899; cv=none; d=google.com; s=arc-20160816; b=ExzOvA52T4QoDVKYz5J23a4Er5wpTU4JSZcGeB3deIuOe1KpZE137qiQItmJYlBJUP pL8xh4UFRGeKKUuy94tOTQK7BiKOtKiMbURo/EpYt8PxzRH930nwWSEuS4dVfAox4SpT vUmCBh9Etga5Q7tGJ5U90PzLXIMC/h+Cm0/ztgdJzYnZbfBMe8niyVsub0RlnOSAoaMh E+Fcvv/xhpyoKHrP6aX1hbNTmEhry+Iatr93vyG614LY8hLK6C2B0PLfkOcikpRu9dvP hL0y47CGmG9vRsljJuTr6AE5sPOhe6/WlMchRzmy1l5JVEkRYcuk1xxFwwGJyiy9E4c7 LDag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sBT1GdX/ck41P3XVpQPpxv9InfpW1WKq1Jtu5cu1e4I=; b=Wd3ErYfVjB1FZm5daZ5rrVqiz9Egchrpj5621oJZc8/49yBuMUEyKhyNGIbVWdWj1z VmtI2gtKSWv93aP8JQPGVDsSkRmBG/ndcmecoyQBKvaWNF+WwvkSFqmaChalpduwqH8t j9lHDQ7isWAZ1iXi2fiuK1KvKHmQKwqBZm/rIWQbwk02ZuNLJ4qucbyq6YrZsaB+7eC8 pceTFkFJBJcWNnug+gwIhghYe+AZcqpnLKW+G4xf/PTqrO5f9QwEjEgldSQPppwO4620 hF9kDPVsDERWcHgHzYgNw91aRUCNT3CFvGPFpcdMlMn7yYsZ+zG8BeSWywHD6SPVWwX/ 7lGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yf271LVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3si18590452pgc.786.2022.02.21.06.31.24; Mon, 21 Feb 2022 06:31:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yf271LVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348913AbiBUJLu (ORCPT + 99 others); Mon, 21 Feb 2022 04:11:50 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347597AbiBUJIL (ORCPT ); Mon, 21 Feb 2022 04:08:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17B7E31937; Mon, 21 Feb 2022 01:00:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A02DF6114D; Mon, 21 Feb 2022 09:00:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85876C340E9; Mon, 21 Feb 2022 09:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645434013; bh=xZYE2z/3Mtqx4OEfbquT0eJ/0vGdq8+qsH6qrEwu3Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yf271LVtP3KUTwiY4Dkdjv7z5Kcw6NAul86iNoJ86Cc3IJauhtRMfbrPEW1Wje3ja xO/OIZYo6Hm0WEGhiuunVLJugrehbe/p20zsvhiK8TyCJvxoexgppFMte9Tq6Jh6ec jxnRr76/c+zdokLZOsNucqceNfSeBTwovYdXPsbQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Eric W. Biederman" , Waiman Long , Christian Brauner Subject: [PATCH 5.4 63/80] copy_process(): Move fd_install() out of sighand->siglock critical section Date: Mon, 21 Feb 2022 09:49:43 +0100 Message-Id: <20220221084917.653609458@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long commit ddc204b517e60ae64db34f9832dc41dafa77c751 upstream. I was made aware of the following lockdep splat: [ 2516.308763] ===================================================== [ 2516.309085] WARNING: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected [ 2516.309433] 5.14.0-51.el9.aarch64+debug #1 Not tainted [ 2516.309703] ----------------------------------------------------- [ 2516.310149] stress-ng/153663 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire: [ 2516.310512] ffff0000e422b198 (&newf->file_lock){+.+.}-{2:2}, at: fd_install+0x368/0x4f0 [ 2516.310944] and this task is already holding: [ 2516.311248] ffff0000c08140d8 (&sighand->siglock){-.-.}-{2:2}, at: copy_process+0x1e2c/0x3e80 [ 2516.311804] which would create a new lock dependency: [ 2516.312066] (&sighand->siglock){-.-.}-{2:2} -> (&newf->file_lock){+.+.}-{2:2} [ 2516.312446] but this new dependency connects a HARDIRQ-irq-safe lock: [ 2516.312983] (&sighand->siglock){-.-.}-{2:2} : [ 2516.330700] Possible interrupt unsafe locking scenario: [ 2516.331075] CPU0 CPU1 [ 2516.331328] ---- ---- [ 2516.331580] lock(&newf->file_lock); [ 2516.331790] local_irq_disable(); [ 2516.332231] lock(&sighand->siglock); [ 2516.332579] lock(&newf->file_lock); [ 2516.332922] [ 2516.333069] lock(&sighand->siglock); [ 2516.333291] *** DEADLOCK *** [ 2516.389845] stack backtrace: [ 2516.390101] CPU: 3 PID: 153663 Comm: stress-ng Kdump: loaded Not tainted 5.14.0-51.el9.aarch64+debug #1 [ 2516.390756] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 2516.391155] Call trace: [ 2516.391302] dump_backtrace+0x0/0x3e0 [ 2516.391518] show_stack+0x24/0x30 [ 2516.391717] dump_stack_lvl+0x9c/0xd8 [ 2516.391938] dump_stack+0x1c/0x38 [ 2516.392247] print_bad_irq_dependency+0x620/0x710 [ 2516.392525] check_irq_usage+0x4fc/0x86c [ 2516.392756] check_prev_add+0x180/0x1d90 [ 2516.392988] validate_chain+0x8e0/0xee0 [ 2516.393215] __lock_acquire+0x97c/0x1e40 [ 2516.393449] lock_acquire.part.0+0x240/0x570 [ 2516.393814] lock_acquire+0x90/0xb4 [ 2516.394021] _raw_spin_lock+0xe8/0x154 [ 2516.394244] fd_install+0x368/0x4f0 [ 2516.394451] copy_process+0x1f5c/0x3e80 [ 2516.394678] kernel_clone+0x134/0x660 [ 2516.394895] __do_sys_clone3+0x130/0x1f4 [ 2516.395128] __arm64_sys_clone3+0x5c/0x7c [ 2516.395478] invoke_syscall.constprop.0+0x78/0x1f0 [ 2516.395762] el0_svc_common.constprop.0+0x22c/0x2c4 [ 2516.396050] do_el0_svc+0xb0/0x10c [ 2516.396252] el0_svc+0x24/0x34 [ 2516.396436] el0t_64_sync_handler+0xa4/0x12c [ 2516.396688] el0t_64_sync+0x198/0x19c [ 2517.491197] NET: Registered PF_ATMPVC protocol family [ 2517.491524] NET: Registered PF_ATMSVC protocol family [ 2591.991877] sched: RT throttling activated One way to solve this problem is to move the fd_install() call out of the sighand->siglock critical section. Before commit 6fd2fe494b17 ("copy_process(): don't use ksys_close() on cleanups"), the pidfd installation was done without holding both the task_list lock and the sighand->siglock. Obviously, holding these two locks are not really needed to protect the fd_install() call. So move the fd_install() call down to after the releases of both locks. Link: https://lore.kernel.org/r/20220208163912.1084752-1-longman@redhat.com Fixes: 6fd2fe494b17 ("copy_process(): don't use ksys_close() on cleanups") Reviewed-by: "Eric W. Biederman" Signed-off-by: Waiman Long Signed-off-by: Christian Brauner Signed-off-by: Greg Kroah-Hartman --- kernel/fork.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2182,10 +2182,6 @@ static __latent_entropy struct task_stru goto bad_fork_cancel_cgroup; } - /* past the last point of failure */ - if (pidfile) - fd_install(pidfd, pidfile); - init_task_pid_links(p); if (likely(p->pid)) { ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace); @@ -2234,6 +2230,9 @@ static __latent_entropy struct task_stru syscall_tracepoint_update(p); write_unlock_irq(&tasklist_lock); + if (pidfile) + fd_install(pidfd, pidfile); + proc_fork_connector(p); cgroup_post_fork(p); cgroup_threadgroup_change_end(current);