Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3378029ybp; Sun, 6 Oct 2019 10:36:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkMTImeYEs6fgtMfZ2Ws6k/h7iDqPQVCdfo50mYh+0YfieFAp1plArpRCsSZt1o6UO6GUs X-Received: by 2002:a17:906:b2d4:: with SMTP id cf20mr20085341ejb.152.1570383401437; Sun, 06 Oct 2019 10:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383401; cv=none; d=google.com; s=arc-20160816; b=091uR2OEq2xLpkNM5SpA6oK08yaq4egdCtqv1eo9v6F8soG6DF++Zoqhl84ekZ6usW yBgnLtOGBlwNB3wcfQ8ASc1YCYtHeAKaDQUpw2a4IfFwa314709KMffB00cOFBLjn8il 3ltox7qrH/3x3iX7JaRgaLybKujOqaNvf+eVsWCdfROOdUk1+T8JniSTEnb8Uu9o3UWx WSyuEg6CQs6/jK4q+jycSQkb7AuSqqcYZYU7dnQOff/lTOWimJ1gUgB3KseeaV24niGj rheMAaY/lHPdXUAHeW5YIA5pGR5BawbJ8YNQ6UBzmjmHkk054BouCfBYoGLjU4WcfC5o Ex1A== 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=Fv7V8Imt5+F41Um5MtYkrKs39AWTIEeMCSHPWIA5qIQ=; b=0F0P3MKvLJmYhNU10HFRrd+50F/sz12PIrozFjP53sYC2HJKrjTPBoR2T9gjshNWFM BVTxs3y20xqH10ycPlc820p8sJzrHmNOsXgOk2TxRVeMmnffFNz/mrc3jCTuXnJ9cpWI TiCJqoU4JsI4fbTGNcHuQA8Na9vd8zPDjavXLtENiKBeQRLr0knr/Do8iHaxoeUvjpfB 28gPZ4UzE5Jw4pnl1rV0XV2mVjnGrOmIYuvY/26KaUBntFvZi5q6JkShrKGk4ll9PRTa RZVCUcZO5SNSKjrlymh6DaRqDYBZqZSovOt04AFVt7za5fxZyaaLdRdRTzBtsYD2w5pE G1eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZoJvT9tS; 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 e22si5740338ejr.19.2019.10.06.10.36.17; Sun, 06 Oct 2019 10:36:41 -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=ZoJvT9tS; 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 S1729609AbfJFRcf (ORCPT + 99 others); Sun, 6 Oct 2019 13:32:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:59082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729597AbfJFRce (ORCPT ); Sun, 6 Oct 2019 13:32:34 -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 D08B7217F9; Sun, 6 Oct 2019 17:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383154; bh=PerffFRqonaHaOoAW5C1zA3Mgfcqrt/j7OprLkUruW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZoJvT9tS6Keg8p6YNiOIwqNHpv0+tnLBo5IyZq/BOc/5jPPLhp5obdZVg6tWQV7Am u3vV55btUvA51QdiWG6zbOaugj8ZOwrJyhdr66wuUjWqrdUlKoBVVHeOTDL3Fts8Ux ZMFLBP/zNVklT7uez3AJC55wszzxpeoJ+Cnf4f7M= 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 4.19 106/106] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie Date: Sun, 6 Oct 2019 19:21:52 +0200 Message-Id: <20191006171204.990638511@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@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 @@ -66,6 +66,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; } }