Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2686734ybl; Thu, 29 Aug 2019 11:28:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3gDkI13c2BVXfz0hDxNkCDb6B3GVsYYAw5qPz0iz74E+UfCbVD/d2apRnNRDPL+LlVbYS X-Received: by 2002:a62:764f:: with SMTP id r76mr12943453pfc.149.1567103309306; Thu, 29 Aug 2019 11:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103309; cv=none; d=google.com; s=arc-20160816; b=mG+8TonE0IPL1FMevmLMU5G6F3dQDNQ/fT4dhqqK7TgWcOIEtGHDrhAskYnf27pkZe aogsGKUrHUk8jrOUNNN1R8MNP8ALb5i9wuzW38yzNqu+jnPPrdk+yv1D8ljfnqdkB7a3 Afr2i9rFNmQlNmBoBDdIBzfnDeSGOc0fltSxPMt88pffjrRGaP+edAszHPkPOyqXM99O rL3ViWkSp1xuiFnCBgK61EWu+QNLNprI90DPKE2/BItCKRgbdzxnQo7CfRb4OzR13OvQ HskGOT1ZRE5au/6AcULyoQtusT1BiFuXwn1NOP3xa0pSmZ1RL3HJ4vhtSDDlo/WfO+st eCxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1ZQ/QgY4zI5mz7YEgJPN05ritKl+GpzBXw1JbhOmNEI=; b=IPd4Qg1560hdlmTqSQK2IyNr42OAAUpfNIEpkoMj9d9x/fJLZdZz9NLTTE/0cyIMp6 Rl/pteYaPfLHiZWHVXW2XgM2uFUmz0EaqOsnCeLI7G9D7VApc8k2QknBg+2CqaElkAo0 IWstn9D1LxJDoiJC9jn3lXNUNMtacMqdzCx3gViCt+nNPgv6ZvSkZ4ydzsNe8mSy3iWZ H5JWf+LSayBtJtH2+/SkA7lL3qOgQ5n+Wu6D4ULHKLIJhen1XnJW+mRDPJ3tcjZ3HdGy +kl3TK1WRMd9SohgqiGbwx5maSJhU+FmUCdz80OKPdU7Q90B8rwWOZ1md1lyL7plK2gb yTpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A+JsQlVX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y16si2671209plp.70.2019.08.29.11.28.14; Thu, 29 Aug 2019 11:28:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A+JsQlVX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729370AbfH2SPh (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:57302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbfH2SPg (ORCPT ); Thu, 29 Aug 2019 14:15:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EB83423404; Thu, 29 Aug 2019 18:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102535; bh=JvqJEB55stf2gf4IFOdP9UEaXddRwXadDHyrHsyqYa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A+JsQlVX8kGVgjvXj19Xp1yVSF9sC7SKtrGXa74UtY5tRc68KZY1V4bJ5zld6HgGi 7Izc/4+Niv9rk52BDjKDqOFTmdpxzzpwmywVQYcoV0PvF9E6gJC1uq7StXxUFXkXVv BM+x1WWAHTvyDpA5JM6EUmDaXpsfoYm3dOOr8SDY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Howells , Sasha Levin , linux-afs@lists.infradead.org Subject: [PATCH AUTOSEL 5.2 70/76] afs: Fix leak in afs_lookup_cell_rcu() Date: Thu, 29 Aug 2019 14:13:05 -0400 Message-Id: <20190829181311.7562-70-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ 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