Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1235220pxu; Mon, 23 Nov 2020 15:31:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0Ufm6aFfFxriWQua7tFq9ssGYYi4CIdGjhle2LO+pzAONpEDztr6mMBt7SlEoBZIclGIM X-Received: by 2002:a17:906:6a51:: with SMTP id n17mr1848925ejs.478.1606174289277; Mon, 23 Nov 2020 15:31:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174289; cv=none; d=google.com; s=arc-20160816; b=xtRzI3l287BJEQ869W/VVnsniPZ4qsq8TSM/alZuraUMSrkhk6Nrjog8VjIa1GUL8+ DxDy/u6ckDUQ0SYL3nnB1wVniVzRyxXDPDA8iF811qdYdhfdxwUkuTRymoedFnFKSGX8 rI8p24qBKOdHMwgH6tO9+G+xF6vN++3Hb7S/2u0xjRfbGbBi89J1iTnEtG3EVt+UsA+a 7Gkk6R7+i1bMaT/w9LNXViq2hZOTofRQFiB6T6GQyEn3ob53EuSRrBaglm5wONEORXLC aIWNmBaiQVaFbzAbIMrk6IeszJ1+K7CKXQieHljr//IJBNPX9H87Oijjh19aBRkfpWBt oh7A== 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=hQSuqX98ahGnDsr3AORGsFzvem7V+LxVsKSCekm9fMQ=; b=OzYkvIThvbGb/1t2XoGu9ZmV0hvqifBriSBoi08xKzY6/NWdcaJVKpx5Ndk+mj8bdj 4GgEDusABHqqPPqOSXysVIUkgrzHHr+9OSgXvuv2xPwD64wF5Ry7vczRoq/SYBcblc4p XoBW1jE78Jt9WLaZXTDeF+KfhFLoURksqgBKZmJSgEfIrFu6p7z7H+QrqlJ2QIUmYJCh oF0M9OVTG6/k/8jxvy6ggQju15GNteqXqzhEPzsp67IYEn1dhNHRPJtv8YGqM1VJEEVv J+AFCVcmsCSsk+tvEAu1/M6ava/9VpWl2IKgKb6gvKZZnJNtSYlDNCtUpjrhRfl1lsaQ xleQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="GvjM/TXf"; 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 i20si4980461ejx.153.2020.11.23.15.31.06; Mon, 23 Nov 2020 15:31:29 -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=@linuxfoundation.org header.s=korg header.b="GvjM/TXf"; 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 S1729737AbgKWMYE (ORCPT + 99 others); Mon, 23 Nov 2020 07:24:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:33204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729392AbgKWMX6 (ORCPT ); Mon, 23 Nov 2020 07:23:58 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE73020728; Mon, 23 Nov 2020 12:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134236; bh=JLV7i0iE59znI1YTofn4MT2DrRVEgleQSnPTsDnKlxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GvjM/TXfkBBKhkodEoQgH1Revr4zkyCRd/7qU1dEhyTJYK59fpGwAUu1l9KlAF1ah e99jzBZXq9MIsnc8vjua7VB2P+/vu6yabRGB+FS+XKmTmiD5fEBqGEmCysurEbPgCn J46DjD4Ya3MzGbUn+mELhKTWsdOYX3akj82HVuJ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+32c6c38c4812d22f2f0b@syzkaller.appspotmail.com, syzbot+4c81fe92e372d26c4246@syzkaller.appspotmail.com, syzbot+6a7fe9faf0d1d61bc24a@syzkaller.appspotmail.com, syzbot+abed06851c5ffe010921@syzkaller.appspotmail.com, syzbot+b7aeb9318541a1c709f1@syzkaller.appspotmail.com, syzbot+d5a9416c6cafe53b5dd0@syzkaller.appspotmail.com, Johannes Berg Subject: [PATCH 4.4 36/38] mac80211: free sta in sta_info_insert_finish() on errors Date: Mon, 23 Nov 2020 13:22:22 +0100 Message-Id: <20201123121806.020431361@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121804.306030358@linuxfoundation.org> References: <20201123121804.306030358@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 commit 7bc40aedf24d31d8bea80e1161e996ef4299fb10 upstream. If sta_info_insert_finish() fails, we currently keep the station around and free it only in the caller, but there's only one such caller and it always frees it immediately. As syzbot found, another consequence of this split is that we can put things that sleep only into __cleanup_single_sta() and not in sta_info_free(), but this is the only place that requires such of sta_info_free() now. Change this to free the station in sta_info_insert_finish(), in which case we can still sleep. This will also let us unify the cleanup code later. Cc: stable@vger.kernel.org Fixes: dcd479e10a05 ("mac80211: always wind down STA state") Reported-by: syzbot+32c6c38c4812d22f2f0b@syzkaller.appspotmail.com Reported-by: syzbot+4c81fe92e372d26c4246@syzkaller.appspotmail.com Reported-by: syzbot+6a7fe9faf0d1d61bc24a@syzkaller.appspotmail.com Reported-by: syzbot+abed06851c5ffe010921@syzkaller.appspotmail.com Reported-by: syzbot+b7aeb9318541a1c709f1@syzkaller.appspotmail.com Reported-by: syzbot+d5a9416c6cafe53b5dd0@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/20201112112201.ee6b397b9453.I9c31d667a0ea2151441cc64ed6613d36c18a48e0@changeid Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/sta_info.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -583,7 +583,7 @@ static int sta_info_insert_finish(struct out_drop_sta: local->num_sta--; synchronize_net(); - __cleanup_single_sta(sta); + cleanup_single_sta(sta); out_err: mutex_unlock(&local->sta_mtx); kfree(sinfo); @@ -602,19 +602,13 @@ int sta_info_insert_rcu(struct sta_info err = sta_info_insert_check(sta); if (err) { + sta_info_free(local, sta); mutex_unlock(&local->sta_mtx); rcu_read_lock(); - goto out_free; + return err; } - err = sta_info_insert_finish(sta); - if (err) - goto out_free; - - return 0; - out_free: - sta_info_free(local, sta); - return err; + return sta_info_insert_finish(sta); } int sta_info_insert(struct sta_info *sta)