From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C0B1C4332F for ; Sun, 8 Sep 2019 12:54:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 28DB920693 for ; Sun, 8 Sep 2019 12:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947244; bh=5f3tIEcfN6OHbaef9X5xk4AMcyhVxSEKQEVstQVO5Lc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=fuXbc5+JustnJ8mKY4FxpPRJgmy0R9rPLRR7FEXPk8ZF5FMcSI58r/qo6qFu2cK1v FEYmMQwHQo+r65TEMKxgFh7P1re3oHW7NN/t8w/P1RXkon5XZSKh8vZgzkSxPdcvAm miPV57yxOjl1KzBNJXVlc/GtB7qg29vq1kYoHSUE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733171AbfIHMwn (ORCPT ); Sun, 8 Sep 2019 08:52:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:45174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733170AbfIHMwn (ORCPT ); Sun, 8 Sep 2019 08:52:43 -0400 Received: from localhost (unknown [62.28.240.114]) (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 085DB2190F; Sun, 8 Sep 2019 12:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947162; bh=5f3tIEcfN6OHbaef9X5xk4AMcyhVxSEKQEVstQVO5Lc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nr0nkbaqUBXLK+0cnNa6GGo8yLCT6SdD6W+3BfA3pBCtnHe4z0HjT1CqKJDF8XMq2 B4iZNuVnnvCiiVomzrzaMDwUwQ47UjR9MTNzCpRzxI19viQIyAyMNcoEUBmns1kkUa FPf3Rs7JevYoo+nJ//dwqUicfnmMUx8tum4fFhNE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Sasha Levin Subject: [PATCH 5.2 84/94] afs: Fix leak in afs_lookup_cell_rcu() Date: Sun, 8 Sep 2019 13:42:20 +0100 Message-Id: <20190908121152.838191654@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121150.420989666@linuxfoundation.org> References: <20190908121150.420989666@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit a5fb8e6c02d6a518fb2b1a2b8c2471fa77b69436 ] Fix a leak on the cell refcount in afs_lookup_cell_rcu() due to non-clearance of the default error in the case a NULL cell name is passed and the workstation default cell is used. Also put a bit at the end to make sure we don't leak a cell ref if we're going to be returning an error. This leak results in an assertion like the following when the kafs module is unloaded: AFS: Assertion failed 2 == 1 is false 0x2 == 0x1 is false ------------[ cut here ]------------ kernel BUG at fs/afs/cell.c:770! ... RIP: 0010:afs_manage_cells+0x220/0x42f [kafs] ... process_one_work+0x4c2/0x82c ? pool_mayday_timeout+0x1e1/0x1e1 ? do_raw_spin_lock+0x134/0x175 worker_thread+0x336/0x4a6 ? rescuer_thread+0x4af/0x4af kthread+0x1de/0x1ee ? kthread_park+0xd4/0xd4 ret_from_fork+0x24/0x30 Fixes: 989782dcdc91 ("afs: Overhaul cell database management") Signed-off-by: David Howells Signed-off-by: Sasha Levin --- fs/afs/cell.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/afs/cell.c b/fs/afs/cell.c index a2a87117d2626..fd5133e26a38b 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -74,6 +74,7 @@ struct afs_cell *afs_lookup_cell_rcu(struct afs_net *net, cell = rcu_dereference_raw(net->ws_cell); if (cell) { afs_get_cell(cell); + ret = 0; break; } ret = -EDESTADDRREQ; @@ -108,6 +109,9 @@ struct afs_cell *afs_lookup_cell_rcu(struct afs_net *net, done_seqretry(&net->cells_lock, seq); + if (ret != 0 && cell) + afs_put_cell(net, cell); + return ret == 0 ? cell : ERR_PTR(ret); } -- 2.20.1