Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3393562ybp; Sun, 6 Oct 2019 10:58:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxu1dKS4Pk9KUV0lNSyVwy4dz0WLvQ5Y0vOuA6ZZayjujP0m6D30XBqV8dfeNTKG1pl0BOx X-Received: by 2002:a17:906:1659:: with SMTP id n25mr20908539ejd.258.1570384693079; Sun, 06 Oct 2019 10:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384693; cv=none; d=google.com; s=arc-20160816; b=oEy19GtPIWAGrQOHqosh30EVN8k5lVuPySQfZfXLe3RM3a0nhUx2JtS8xJoSsvfQta dER0tcgUKDRTjdrJho119xodGJHDQ/kaFtioe4Pje6w3DyCui6o/i4Qfydflp3FCf27N Z5OPZ+8eXZ9WHH1t8SO/hdvBppjUufXLBaIjwU4v0q30yNdDa/QfcFtsSgB7Rq76Q2mK azB0CxWRhdCteJuaKkocN8sRskBLHCbGSSmir3S2xpNRV+taHN3m3aQW45IBl1TgvnOv ESMboKAxYIoqzjO/RYY+2AAm0sdb7mnXr87ULMaCz4YnNCeSrMQLbloZB6PD/xwcyrmo ychA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yZS3yQPN+wZKG/W8baiK0BCtptGvLLTJnrescWXdG1E=; b=YFNRGTIhxHqmIcVrNyTFeB0PtdhWqINjmNcvYu2cOa4WoxSuoR3MQn3vmiN0T8jxQn Nb4EKixtFIvlL9nSrhjzK/AqS1U3lZeZqRFn9jZiLcMdQ1J8Ko4ReaJRH+7AP6W2yq9W kPJb9lvYuR9A+7LlcAg3cZNgW08wzQiXe3x/i1dm1iJ9fLZXBCKf11Hj90smkjRlBTCA F6MAq6GWfnyHR30Irq0Csl6mcAuRvo9T7PRRVgznvpqWl3smhxWPLXMver9Ww3e2gNng pscqbVcq9qzii7ReWWVZWXkVOHbwcYSjP1FfcXqDt1R7Yyd+MJT3K2lNFewo7ktcE1fY mNLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CNO9bKJ0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14si7435052eda.104.2019.10.06.10.57.49; Sun, 06 Oct 2019 10:58:13 -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=CNO9bKJ0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbfJFRzC (ORCPT + 99 others); Sun, 6 Oct 2019 13:55:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:51348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728703AbfJFRya (ORCPT ); Sun, 6 Oct 2019 13:54:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 989622246F; Sun, 6 Oct 2019 17:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383979; bh=bDeYkcfrCcYDblr5V5cTyF4lXsdHjxrarOQYWZLL9S0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CNO9bKJ0rFlbDnxliCl1NzI/YcigZu1XLEN6Avr9YmoCMtDCkJbHn+rdQ/ctz14SH TZR4J+VPTjC0knYioZsEOoUf4KTPTCLIXAGh+Eezmvxd+QlBZHBJDcMfxoDUrU81If T+7T8rjksOfgNrmGH943xrKCUhdqWWvtVL7zYyeo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+3a030a73b6c1e9833815@syzkaller.appspotmail.com, Bharath Vedartham , Dominique Martinet Subject: [PATCH 5.3 165/166] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie Date: Sun, 6 Oct 2019 19:22:11 +0200 Message-Id: <20191006171226.753077885@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bharath Vedartham commit 962a991c5de18452d6c429d99f3039387cf5cbb0 upstream. v9fs_cache_session_get_cookie assigns a random cachetag to v9ses->cachetag, if the cachetag is not assigned previously. v9fs_random_cachetag allocates memory to v9ses->cachetag with kmalloc and uses scnprintf to fill it up with a cachetag. But if scnprintf fails, v9ses->cachetag is not freed in the current code causing a memory leak. Fix this by freeing v9ses->cachetag it v9fs_random_cachetag fails. This was reported by syzbot, the link to the report is below: https://syzkaller.appspot.com/bug?id=f012bdf297a7a4c860c38a88b44fbee43fd9bbf3 Link: http://lkml.kernel.org/r/20190522194519.GA5313@bharath12345-Inspiron-5559 Reported-by: syzbot+3a030a73b6c1e9833815@syzkaller.appspotmail.com Signed-off-by: Bharath Vedartham Signed-off-by: Dominique Martinet Signed-off-by: Greg Kroah-Hartman --- fs/9p/cache.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/9p/cache.c +++ b/fs/9p/cache.c @@ -51,6 +51,8 @@ void v9fs_cache_session_get_cookie(struc if (!v9ses->cachetag) { if (v9fs_random_cachetag(v9ses) < 0) { v9ses->fscache = NULL; + kfree(v9ses->cachetag); + v9ses->cachetag = NULL; return; } }