Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2635261pxj; Mon, 14 Jun 2021 03:38:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXSfzgzt+4mCS2aSFbJ7TyYZSzd5F/IsvaeHTc8nmHnZskmECARbQLdKHkJMczb05UOszs X-Received: by 2002:a05:6402:40c3:: with SMTP id z3mr16052148edb.187.1623667110780; Mon, 14 Jun 2021 03:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623667110; cv=none; d=google.com; s=arc-20160816; b=NwYhSz3wvCneXADDO6zpOkuLSclt9f/gl/9hU8lDQ1r0vsOAhzkC1swZJGa9ehRRBh fg7BQWxMcijWzWydl6lqyuXPNEBnvVTCbvX1dyx/oKNOKWmC9Q43yXO6CuZLP09TDhuR VSPuc+NigyKKNk15K3Ol62NRD4DE89h/tPDliuG0SXzDteQA/xmeR92LfKJhYeMpljTZ mGAdbss1j0OkYPYsH9Qf9kgxQd+HPY0ceYBj5y0XxupM5y4k32oQ26Xy3aXgwk/TZBgL YoeTMQbgS75YkUD60BNqBCszWfkvObFIlFDyCOQVadZDzSPeNGWFMuerNtnQU+N/UoX6 7ueQ== 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=W2bathFH4Rm0L2zX9ubW1v6LrgXSK7n6oCM2zKuPgUE=; b=SMVqMoQ9opCg+JqKpC62SLAe2vUs7Vgosib5p3SKpPc867WznFEXhOe7Ze3bJ+rN/K POoj53cJd9Ws4eiUkotaTbs07hf6ECk/yiXvQE6Xk6dN3YqixjbG7ZHEbNj+C3wv2/xj Rivmlb6ZXzqhFIGVZY0yJTdlp2p4QXWzJOgHVpiOcLAq9EKZ1hC/ndytAPltlMC3UB5j O3Lo7ZsuKvh4kebX0kgX5nNXbDgyCtiaMOr0YZQ8qiCCRWlHKVmsv4QoGHL6J8IPE7Cn yYQy/kv0XoBf0KSBsqHAIj+/tjEUOhy0lFo6VD/I1j4N6F1THw7XVSXL72EiwCG2IH5l 4sbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P+GrKrrP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si3680442ede.514.2021.06.14.03.38.08; Mon, 14 Jun 2021 03:38:30 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=P+GrKrrP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233577AbhFNKgJ (ORCPT + 99 others); Mon, 14 Jun 2021 06:36:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:40438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233317AbhFNKdk (ORCPT ); Mon, 14 Jun 2021 06:33:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FF6D6134F; Mon, 14 Jun 2021 10:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623666683; bh=g4c31cHzQDbqDDuOrRuefwngoa8CJFoOdHRLyYsOp/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P+GrKrrPwnaxHxFKUJ21qVo3hecI82pbuhCrCKYn801YyESHbU90m9fUslFJC7stQ NJcJM2483PXjMeAI2+u4MY4SDFCKpsn8i1050UiSWU0MvAsxm2nZt2pvMgIBYewlXK u/ylBhSEPHN8NtbkzSPdu5qA18i3bvBZYTQZXnmI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+69ff9dff50dcfe14ddd4@syzkaller.appspotmail.com, Johannes Berg , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 06/42] netlink: disable IRQs for netlink_lock_table() Date: Mon, 14 Jun 2021 12:26:57 +0200 Message-Id: <20210614102642.910735239@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102642.700712386@linuxfoundation.org> References: <20210614102642.700712386@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg [ Upstream commit 1d482e666b8e74c7555dbdfbfb77205eeed3ff2d ] Syzbot reports that in mac80211 we have a potential deadlock between our "local->stop_queue_reasons_lock" (spinlock) and netlink's nl_table_lock (rwlock). This is because there's at least one situation in which we might try to send a netlink message with this spinlock held while it is also possible to take the spinlock from a hardirq context, resulting in the following deadlock scenario reported by lockdep: CPU0 CPU1 ---- ---- lock(nl_table_lock); local_irq_disable(); lock(&local->queue_stop_reason_lock); lock(nl_table_lock); lock(&local->queue_stop_reason_lock); This seems valid, we can take the queue_stop_reason_lock in any kind of context ("CPU0"), and call ieee80211_report_ack_skb() with the spinlock held and IRQs disabled ("CPU1") in some code path (ieee80211_do_stop() via ieee80211_free_txskb()). Short of disallowing netlink use in scenarios like these (which would be rather complex in mac80211's case due to the deep callchain), it seems the only fix for this is to disable IRQs while nl_table_lock is held to avoid hitting this scenario, this disallows the "CPU0" portion of the reported deadlock. Note that the writer side (netlink_table_grab()) already disables IRQs for this lock. Unfortunately though, this seems like a huge hammer, and maybe the whole netlink table locking should be reworked. Reported-by: syzbot+69ff9dff50dcfe14ddd4@syzkaller.appspotmail.com Signed-off-by: Johannes Berg Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/netlink/af_netlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 205865292ba3..541410f1c3b7 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -436,11 +436,13 @@ void netlink_table_ungrab(void) static inline void netlink_lock_table(void) { + unsigned long flags; + /* read_lock() synchronizes us to netlink_table_grab */ - read_lock(&nl_table_lock); + read_lock_irqsave(&nl_table_lock, flags); atomic_inc(&nl_table_users); - read_unlock(&nl_table_lock); + read_unlock_irqrestore(&nl_table_lock, flags); } static inline void -- 2.30.2