From: Taesoo Kim <tsgatesv@gmail.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: taesoo@gatech.edu, changwoo@gatech.edu, sanidhya@gatech.edu,
blee@gatech.edu, csong84@gatech.edu,
Taesoo Kim <tsgatesv@gmail.com>
Subject: [PATCH 1/1] ext4: better error handling of kstrdup()
Date: Fri, 20 Mar 2015 17:21:54 -0400 [thread overview]
Message-ID: <1426886514-23522-1-git-send-email-tsgatesv@gmail.com> (raw)
Upon memory pressure, kstrdup() might fail and correctly
handle memory error, although current implementation do not
refer orig_data.
NOTE. fortunately the correct impl works, other than a
corner case where kstrdup() fails and kzalloc() succeeds;
it might record 'NULL' in the log.
Signed-off-by: Taesoo Kim <tsgatesv@gmail.com>
---
fs/ext4/super.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e061e66..e2a609c 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3408,7 +3408,7 @@ static int ext4_reserve_clusters(struct ext4_sb_info *sbi, ext4_fsblk_t count)
static int ext4_fill_super(struct super_block *sb, void *data, int silent)
{
- char *orig_data = kstrdup(data, GFP_KERNEL);
+ char *orig_data;
struct buffer_head *bh;
struct ext4_super_block *es = NULL;
struct ext4_sb_info *sbi;
@@ -3431,6 +3431,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
ext4_group_t first_not_zeroed;
+ orig_data = kstrdup(data, GFP_KERNEL);
+ if (!orig_data)
+ return -ENOMEM;
+
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi)
goto out_free_orig;
@@ -4843,6 +4847,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
int i, j;
#endif
char *orig_data = kstrdup(data, GFP_KERNEL);
+ if (!orig_data)
+ return -ENOMEM;
/* Store the original options */
old_sb_flags = sb->s_flags;
--
2.3.3
next reply other threads:[~2015-03-20 21:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 21:21 Taesoo Kim [this message]
2015-04-03 4:25 ` [PATCH 1/1] ext4: better error handling of kstrdup() Theodore Ts'o
2015-04-03 5:09 ` Theodore Ts'o
2015-04-03 17:44 ` Taesoo Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426886514-23522-1-git-send-email-tsgatesv@gmail.com \
--to=tsgatesv@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=blee@gatech.edu \
--cc=changwoo@gatech.edu \
--cc=csong84@gatech.edu \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sanidhya@gatech.edu \
--cc=taesoo@gatech.edu \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.