From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751781AbbCTVWD (ORCPT ); Fri, 20 Mar 2015 17:22:03 -0400 Received: from mail-qg0-f50.google.com ([209.85.192.50]:33397 "EHLO mail-qg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbbCTVWB (ORCPT ); Fri, 20 Mar 2015 17:22:01 -0400 From: Taesoo Kim 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 Subject: [PATCH 1/1] ext4: better error handling of kstrdup() Date: Fri, 20 Mar 2015 17:21:54 -0400 Message-Id: <1426886514-23522-1-git-send-email-tsgatesv@gmail.com> X-Mailer: git-send-email 2.3.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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