Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3382816ybp; Sun, 6 Oct 2019 10:43:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+K2HNgMHv0M7ZpMvGld1gUzn/5YfRz7s8or5QPa98kDrKyZE0E41+F5JGNKuoIG7YUiVd X-Received: by 2002:a17:906:c7d4:: with SMTP id dc20mr20593129ejb.235.1570383780516; Sun, 06 Oct 2019 10:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383780; cv=none; d=google.com; s=arc-20160816; b=tmNSDB/Aw3RJridI3N3o4xvtiYA23cubdMVXcJCB2mqHk82ZWGXFPhpotC7uCSq414 fCsWeIpBg5WyoAIBmjgR99BfjMb6tRzaaQvEd9tGgX0OZD01crM/bFnxyQSblGbuBG8M OXN9ohXNEiS21OUCyy2aNTYWPH/a0djtvZ5FA0kM1G2cP+Z9HIItc2nIj0FzBdTCCu2e y+aitZS8QyvCbXz7MQYE30k0BuOQukcDSZvwt6O2epXpubsfJQIQkOdM/078vbVAD65m YIOHmgd46VPDV5Bxxy741lgamR7DOBXbHagkwpQOmeKsyXgPw3t80BZZ0n4f9mnorZuJ phxg== 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=gsq42x0e6/4a0fcqoTmUiIiKlAZyQBDPJCoSIaQFM/8/LhrXONlw4xreO4UrWHdh3M ONBz3RcRv+a1kd5cqyuGrsFFUjuh1WJsh4TuxWihgIlRVdk9UpdFKU8nSXrSoaprZRph TlTaCqMMOyvqBj71l4kl1oaM6Q4RhmEG9S+viZsVrTWvlsh7Aa+m99adz4dO+X1cjIdM hQpSGWLFwPNoihG5QksQvEtyTd5koZgMvg1h9A2wq1+vYqGvKOKY/SsDNCuJg7rwCoMh 9kCXfWr5kNVQOMud2OpbmMM3+npL8hFKTzdbvsszqpj/0/ps6huCn/rmxQ9/jQhqZg55 ebTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="15B0J/Wf"; 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 y2si7188663eds.98.2019.10.06.10.42.36; Sun, 06 Oct 2019 10:43:00 -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="15B0J/Wf"; 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 S1730723AbfJFRjG (ORCPT + 99 others); Sun, 6 Oct 2019 13:39:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:38498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730718AbfJFRjE (ORCPT ); Sun, 6 Oct 2019 13:39:04 -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 1CC7E20700; Sun, 6 Oct 2019 17:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383543; bh=bDeYkcfrCcYDblr5V5cTyF4lXsdHjxrarOQYWZLL9S0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=15B0J/WfjomQ2kUc2CmTqQAGKgxXrXyWT81eR/TYM+K4Va+0DGPSDJOXofvyX+LD8 qjVjje46QecxC0M2JI46RSZwYn8jVWRX0rlG0tDj2BewlNzAo/fE4qWtRcBvY0pRaX 2u2ZJotvFDXcCTjpfFFQbhQyab5i2dWndWexOc68= 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.2 136/137] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie Date: Sun, 6 Oct 2019 19:22:00 +0200 Message-Id: <20191006171220.725135196@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@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; } }