Return-Path: Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40535 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932779AbeFGOkL (ORCPT ); Thu, 7 Jun 2018 10:40:11 -0400 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Steve French" , "Namjae Jeon" , "Ashish Sangwan" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: Subject: [PATCH 3.16 170/410] cifs: fix memory leak when password is supplied multiple times In-Reply-To: Sender: stable-owner@vger.kernel.org List-ID: 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Namjae Jeon commit d6ccf4997e62fb6629f9f003980dca5292138b7b upstream. Unlikely but possible. When password is supplied multiple times, we have to free the previous allocation. Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan Signed-off-by: Steve French Signed-off-by: Ben Hutchings --- fs/cifs/connect.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1614,6 +1614,7 @@ cifs_parse_mount_options(const char *mou tmp_end++; if (!(tmp_end < end && tmp_end[1] == delim)) { /* No it is not. Set the password to NULL */ + kfree(vol->password); vol->password = NULL; break; } @@ -1651,6 +1652,7 @@ cifs_parse_mount_options(const char *mou options = end; } + kfree(vol->password); /* Now build new password string */ temp_len = strlen(value); vol->password = kzalloc(temp_len+1, GFP_KERNEL);