Skip to content

Commit 4735d9b

Browse files
Fabian Frederickgregkh
authored andcommitted
jffs2: reduce stack usage in jffs2_build_xattr_subsystem()
commit 1168f09 upstream. Use kcalloc() for allocation/flush of 128 pointers table to reduce stack usage. Function now returns -ENOMEM or 0 on success. stackusage Before: ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 1208 dynamic,bounded After: ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 192 dynamic,bounded Also update definition when CONFIG_JFFS2_FS_XATTR is not enabled Tested with an MTD mount point and some user set/getfattr. Many current target on OpenWRT also suffer from a compilation warning (that become an error with CONFIG_WERROR) with the following output: fs/jffs2/xattr.c: In function 'jffs2_build_xattr_subsystem': fs/jffs2/xattr.c:887:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] 887 | } | ^ Using dynamic allocation fix this compilation warning. Fixes: c9f700f ("[JFFS2][XATTR] using 'delete marker' for xdatum/xref deletion") Reported-by: Tim Gardner <tim.gardner@canonical.com> Reported-by: kernel test robot <lkp@intel.com> Reported-by: Ron Economos <re@w6rz.net> Reported-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Fabian Frederick <fabf@skynet.be> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Cc: stable@vger.kernel.org Message-Id: <20230506045612.16616-1-ansuelsmth@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4868a24 commit 4735d9b

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

fs/jffs2/build.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
211211
ic->scan_dents = NULL;
212212
cond_resched();
213213
}
214-
jffs2_build_xattr_subsystem(c);
214+
ret = jffs2_build_xattr_subsystem(c);
215+
if (ret)
216+
goto exit;
217+
215218
c->flags &= ~JFFS2_SB_FLAG_BUILDING;
216219

217220
dbg_fsbuild("FS build complete\n");

fs/jffs2/xattr.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,10 @@ void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c)
772772
}
773773

774774
#define XREF_TMPHASH_SIZE (128)
775-
void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
775+
int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
776776
{
777777
struct jffs2_xattr_ref *ref, *_ref;
778-
struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE];
778+
struct jffs2_xattr_ref **xref_tmphash;
779779
struct jffs2_xattr_datum *xd, *_xd;
780780
struct jffs2_inode_cache *ic;
781781
struct jffs2_raw_node_ref *raw;
@@ -784,9 +784,12 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
784784

785785
BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
786786

787+
xref_tmphash = kcalloc(XREF_TMPHASH_SIZE,
788+
sizeof(struct jffs2_xattr_ref *), GFP_KERNEL);
789+
if (!xref_tmphash)
790+
return -ENOMEM;
791+
787792
/* Phase.1 : Merge same xref */
788-
for (i=0; i < XREF_TMPHASH_SIZE; i++)
789-
xref_tmphash[i] = NULL;
790793
for (ref=c->xref_temp; ref; ref=_ref) {
791794
struct jffs2_xattr_ref *tmp;
792795

@@ -884,6 +887,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
884887
"%u of xref (%u dead, %u orphan) found.\n",
885888
xdatum_count, xdatum_unchecked_count, xdatum_orphan_count,
886889
xref_count, xref_dead_count, xref_orphan_count);
890+
kfree(xref_tmphash);
891+
return 0;
887892
}
888893

889894
struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,

fs/jffs2/xattr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static inline int is_xattr_ref_dead(struct jffs2_xattr_ref *ref)
7171
#ifdef CONFIG_JFFS2_FS_XATTR
7272

7373
extern void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c);
74-
extern void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
74+
extern int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
7575
extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c);
7676

7777
extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
@@ -103,7 +103,7 @@ extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t);
103103
#else
104104

105105
#define jffs2_init_xattr_subsystem(c)
106-
#define jffs2_build_xattr_subsystem(c)
106+
#define jffs2_build_xattr_subsystem(c) (0)
107107
#define jffs2_clear_xattr_subsystem(c)
108108

109109
#define jffs2_xattr_do_crccheck_inode(c, ic)

0 commit comments

Comments
 (0)