]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
reiserfs: Fix memory leak in reiserfs_parse_options()
authorJan Kara <jack@suse.cz>
Wed, 4 Mar 2020 13:01:44 +0000 (14:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 08:03:11 +0000 (09:03 +0100)
[ Upstream commit e9d4709fcc26353df12070566970f080e651f0c9 ]

When a usrjquota or grpjquota mount option is used multiple times, we
will leak memory allocated for the file name. Make sure the last setting
is used and all the previous ones are properly freed.

Reported-by: syzbot+c9e294bbe0333a6b7640@syzkaller.appspotmail.com
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/reiserfs/super.c

index f9796fd5153153b5e8c127679e9f7cbf29511b9f..503d8c06e0d936231c68975a5452639a0c93059b 100644 (file)
@@ -1232,6 +1232,10 @@ static int reiserfs_parse_options(struct super_block *s,
                                                 "turned on.");
                                return 0;
                        }
+                       if (qf_names[qtype] !=
+                           REISERFS_SB(s)->s_qf_names[qtype])
+                               kfree(qf_names[qtype]);
+                       qf_names[qtype] = NULL;
                        if (*arg) {     /* Some filename specified? */
                                if (REISERFS_SB(s)->s_qf_names[qtype]
                                    && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
@@ -1261,10 +1265,6 @@ static int reiserfs_parse_options(struct super_block *s,
                                else
                                        *mount_options |= 1 << REISERFS_GRPQUOTA;
                        } else {
-                               if (qf_names[qtype] !=
-                                   REISERFS_SB(s)->s_qf_names[qtype])
-                                       kfree(qf_names[qtype]);
-                               qf_names[qtype] = NULL;
                                if (qtype == USRQUOTA)
                                        *mount_options &= ~(1 << REISERFS_USRQUOTA);
                                else