Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2225866rdb; Mon, 9 Oct 2023 18:08:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7JvfgMtYs5LV+mJDBUzg8JyxmyWuaQ4vIbCRsHizA+2TQepFUp7rGv9/anzz37Ph65gSh X-Received: by 2002:a17:90a:af86:b0:277:4be4:7a84 with SMTP id w6-20020a17090aaf8600b002774be47a84mr19755552pjq.19.1696900116389; Mon, 09 Oct 2023 18:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696900116; cv=none; d=google.com; s=arc-20160816; b=KOya9iQpQ7kJ4IzyGjqmTUCbPZ4C1Ls4kzkV6nnWBLv7NhQZRB8jJ/h4LjHCngfq9F 4LowuwnjFjEHk9S6mkRcKL67Aq3cvLONipqvdf32W0GRBEIbMvPrYQ8cf8fiPSuS7wrP cyXwdk15NsMqA5/UTmld3NvBH4u2IYbIKXoq/jDAifxQsd+BA0V/KosURk2uGPxLIpQB PalP+pLxvsaLMe65Ig1OVO4MBWWXIaHGwKWFm/oKO8zCXHejM6FeSyrYAyQbBhpUwCiJ SDuR12THiZxnv1zBF+UnUdHjN6N7vpGOsq7DlY5cpH6OpYSc3uoxdx0cWua+RZznpW4E E5iw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/NyHLoSVe2VzqxLFtpuVYd0zTrzwtQioN6fcJnEB+68=; fh=fd9x9sGDPY/O8OSXn8+ilJ9mGIHo90d6RLV0TOO/F/s=; b=Viwi7CiAPw1aDA+Ifec+Z9HBWU703pAtyPjJvrALXvv2lfIL6AZmutjm84DkPRlxaQ hpEZR8ifn07uFETmDsA2NjY8uq1/Lwzre/L2kL9xsVOwGYh7X1CmTJdmxStfUR/zhS47 avpukGkz3HFlbny9ANfKH5qOj+BYMafKbJGDkvSj1UHMywDt7Bo1c1S/W7VKvN+hEkOU LXuDyZKyJKiNdHBmMhJ5E4WbRtbZVo0ent4Wsy8AoFQfXZDpslZWdDPtJiQihoDBb5Hn T5YO1R+idQ9ibTmhzb4lm1YRWd1UcoB//dcI2aCfm01C1erwumMgm4890IoiY7UMcO4h Rnkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zg3n7NW2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x15-20020a17090a8a8f00b0027b258f284esi9616526pjn.26.2023.10.09.18.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 18:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zg3n7NW2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8D2A18104517; Mon, 9 Oct 2023 18:08:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379323AbjJJBI0 (ORCPT + 99 others); Mon, 9 Oct 2023 21:08:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379287AbjJJBIZ (ORCPT ); Mon, 9 Oct 2023 21:08:25 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD76A9E; Mon, 9 Oct 2023 18:08:23 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2773f776f49so3718053a91.1; Mon, 09 Oct 2023 18:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696900103; x=1697504903; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/NyHLoSVe2VzqxLFtpuVYd0zTrzwtQioN6fcJnEB+68=; b=Zg3n7NW25xQO+Ebzi+0oP6kaw2STOV6fPCUkXTe080xcJaIQ7I/0plThD5oaD4tFzm 5Mu+xGBOQUmJKp9+iBU94lIpi9s5UrMIGXJgi9j7fwa6g6yLhzHUZvk6+0JsK9KySs7F jBO32YlnIykNKHtvYYk7lU1h6YYbNg7uu5JzFMwgY50RKzkycP0nJwjazZqQXstD6crC o0ycC4Vu6h9dQoh2F1i/ifsJWOlp+VosbfGVRUdzMXgHcy6zpJwNSYzkrky1Xc2DuVay h0L6fvgo+MrW3WSK87N4WZOWR5lpbjP/JcxZjXbRJ2sP6yHPF8wBDtI0HSN9tJuRqvCA 5PEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696900103; x=1697504903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/NyHLoSVe2VzqxLFtpuVYd0zTrzwtQioN6fcJnEB+68=; b=UbgihKqOnic8L0lYHFxG8LY4Fn4taUQ7oS0gemqrarictrDEj7SUU4iko7Cg/fKVjk Zclb+vHDkhkB/fg3XnHaXrpr1hutCrns3AU3kdmkdWXW5NEb/bOPan5aop4Z2Ak7wEhB akk/oqnDcNp+4iK8UinkNxQEKDWmdVZUmNdwv9nEqFIRa4dPi3PQHsAdFRDjjuioTxru rkfJEB2j0yv1753h2lyxhHy8adp883EWBZ+xPpzhN3jT+c1JSIrw0K4zZAyGYiHpDlSV +iWgIHPOphmxdOc6B9XoH1uHpud0lOKZdCAaEErS1yHS9+/3dfij0awDJNDjDFZEX2tS pvog== X-Gm-Message-State: AOJu0Yx1R662Z/PuH+Xr8/ZahVQhI05NIeViVu7tRdAGQzgprOHaFFeJ c5yiFj7wqxHQdcAUq+Mc82Q= X-Received: by 2002:a17:90a:dd43:b0:273:83ac:5eb9 with SMTP id u3-20020a17090add4300b0027383ac5eb9mr19693687pjv.4.1696900102964; Mon, 09 Oct 2023 18:08:22 -0700 (PDT) Received: from pek-lxu-l1.wrs.com ([111.198.228.56]) by smtp.gmail.com with ESMTPSA id l6-20020a633e06000000b00589eb5b1df7sm3723822pga.35.2023.10.09.18.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 18:08:22 -0700 (PDT) From: Edward AD To: syzbot+509238e523e032442b80@syzkaller.appspotmail.com Cc: davem@davemloft.net, edumazet@google.com, johannes.berg@intel.com, johannes@sipsolutions.net, kuba@kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, syzkaller-bugs@googlegroups.com Subject: [PATCH] rfkill: fix deadlock in rfkill_send_events Date: Tue, 10 Oct 2023 09:08:15 +0800 Message-ID: <20231010010814.1799012-2-twuufnxlz@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <000000000000e3788c06074e2b84@google.com> References: <000000000000e3788c06074e2b84@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 18:08:35 -0700 (PDT) syzbot report: syz-executor675/5132 is trying to acquire lock: ffff8880297ee088 (&data->mtx){+.+.}-{3:3}, at: rfkill_send_events+0x226/0x3f0 net/rfkill/core.c:286 but task is already holding lock: ffff88801bfc0088 (&data->mtx){+.+.}-{3:3}, at: rfkill_fop_open+0x146/0x750 net/rfkill/core.c:1183 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&data->mtx); lock(&data->mtx); *** DEADLOCK *** In 2c3dfba4cf84 insert rfkill_sync() to rfkill_fop_open(), it will call rfkill_send_events() and then triger this issue. Fixes: 2c3dfba4cf84 ("rfkill: sync before userspace visibility/changes") Reported-and-tested-by: syzbot+509238e523e032442b80@syzkaller.appspotmail.com Signed-off-by: Edward AD --- net/rfkill/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 08630896b6c8..a14e0d4a0b00 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -1180,7 +1180,6 @@ static int rfkill_fop_open(struct inode *inode, struct file *file) init_waitqueue_head(&data->read_wait); mutex_lock(&rfkill_global_mutex); - mutex_lock(&data->mtx); /* * start getting events from elsewhere but hold mtx to get * startup events added first @@ -1191,9 +1190,12 @@ static int rfkill_fop_open(struct inode *inode, struct file *file) if (!ev) goto free; rfkill_sync(rfkill); + mutex_lock(&data->mtx); rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); list_add_tail(&ev->list, &data->events); + mutex_unlock(&data->mtx); } + mutex_lock(&data->mtx); list_add(&data->list, &rfkill_fds); mutex_unlock(&data->mtx); mutex_unlock(&rfkill_global_mutex); -- 2.25.1