Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2733818pxv; Mon, 12 Jul 2021 00:11:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU3axDBMJ/uagOK2pZxVDRNEl5CDP+1rPPQ8FeVYoFWTE5Qq501IZ5dc6IuuTlFUJw4wjh X-Received: by 2002:a05:6638:268d:: with SMTP id o13mr17500518jat.103.1626073821389; Mon, 12 Jul 2021 00:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626073821; cv=none; d=google.com; s=arc-20160816; b=03SW8zJPe3j9NkhwsHgiUm86KidCWj+1iKWf0TJPg6Oxrppw7biURtRgV3nxG2aKRU PEb8MAGUsnnFlbtLgepmkPqhy9qzAhXyHya/xn5H2kmw1zAOTuwRvu0oidM4MyczfD2F T5GMdsBdreMcvHnFTpN1jBY2RcsT/4OM3BjUHuUFRHhcScfhIxUngmqtUK6Si7cp6ntq pzlDD6OLf/95prePplZmMcuoNFurmjUq6llyWEJS0JcbecBXJKFxwbkKng0G/vreQGXa sqyT/EhIbbv7zlabY1Z/S4WDNZ3+7M9XK6WZbAF1YnI7T0baViZhtGFbp6lICinz0p0q UJjA== 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=ncbb//TB/e9mwj6YoNT4e3zGhIUEV3QyjBQ1QNmKMiE=; b=Qv0qzeE7dxOOFKJsEOcIal7Qds7adFUw/reNhx/L6JlL6gbJj9PKGs52Fljm3wdh62 WkXUwzhX7DaMe2iYjsZdicPX6eh04S81pq4xeBK17XzhhzcYytJBXRjiY1KQnxH/TLae tTZYb8LQDVzOQ3Y7hmRWSwwUzGQ6NjDHvCZ7yBVQzPjFOQFYAAQ4hOkhg3BIL90Mu5Vv ixP8tZeX/89P0v8KeH7UVWFH+Lnx50kNyw/+csd0+XwFtRLgTTrKrEYqgQZtiN2CXa62 bf1Nd8uLf4GCyDelHknyaiwGRMIBfymfbIhju1XTiGCs2XLARIIFBYHPEG2/JhlPwbbr 4TYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ngr7tvFG; 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 p18si15168640ios.10.2021.07.12.00.10.09; Mon, 12 Jul 2021 00:10:21 -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=Ngr7tvFG; 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 S244352AbhGLHKj (ORCPT + 99 others); Mon, 12 Jul 2021 03:10:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:48264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238192AbhGLGsd (ORCPT ); Mon, 12 Jul 2021 02:48:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BF4ED61241; Mon, 12 Jul 2021 06:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072262; bh=8eDjzXcloaE/8l5tgHAKTWdZoA2jNyk7sZYlVDT92Hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ngr7tvFGWorLfZlSiuTPfbpPXI/pVfH6YhaVyWjxsMa8pbA+OdNT8q3TQVYmDI4h7 jqVkcdeaYlMBhbfcDQxOV8yxNN3qFjD32B194eJtkkTwPq2ug2zbGsoMG6nFGDXot6 zi7C0sx+aNhSIJf9CF5V3iUTLPTwrjr6mP5WGBxI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+b80c9959009a9325cdff@syzkaller.appspotmail.com, Dongliang Mu , Alexander Aring , Stefan Schmidt , Sasha Levin Subject: [PATCH 5.10 386/593] ieee802154: hwsim: Fix memory leak in hwsim_add_one Date: Mon, 12 Jul 2021 08:09:06 +0200 Message-Id: <20210712060929.560586863@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@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: Dongliang Mu [ Upstream commit 28a5501c3383f0e6643012c187b7c2027ef42aea ] No matter from hwsim_remove or hwsim_del_radio_nl, hwsim_del fails to remove the entry in the edges list. Take the example below, phy0, phy1 and e0 will be deleted, resulting in e1 not freed and accessed in the future. hwsim_phys | ------------------------------ | | phy0 (edges) phy1 (edges) ----> e1 (idx = 1) ----> e0 (idx = 0) Fix this by deleting and freeing all the entries in the edges list between hwsim_edge_unsubscribe_me and list_del(&phy->list). Reported-by: syzbot+b80c9959009a9325cdff@syzkaller.appspotmail.com Fixes: 1c9f4a3fce77 ("ieee802154: hwsim: fix rcu handling") Signed-off-by: Dongliang Mu Acked-by: Alexander Aring Link: https://lore.kernel.org/r/20210616020901.2759466-1-mudongliangabcd@gmail.com Signed-off-by: Stefan Schmidt Signed-off-by: Sasha Levin --- drivers/net/ieee802154/mac802154_hwsim.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c index 7a168170224a..6d479df2d9e5 100644 --- a/drivers/net/ieee802154/mac802154_hwsim.c +++ b/drivers/net/ieee802154/mac802154_hwsim.c @@ -824,12 +824,17 @@ err_pib: static void hwsim_del(struct hwsim_phy *phy) { struct hwsim_pib *pib; + struct hwsim_edge *e; hwsim_edge_unsubscribe_me(phy); list_del(&phy->list); rcu_read_lock(); + list_for_each_entry_rcu(e, &phy->edges, list) { + list_del_rcu(&e->list); + hwsim_free_edge(e); + } pib = rcu_dereference(phy->pib); rcu_read_unlock(); -- 2.30.2