Skip to content

Commit 7afb6d8

Browse files
andy-shevkees
authored andcommitted
jbd2: Avoid printing outside the boundary of the buffer
Theoretically possible that "%pg" will take all room for the j_devname and hence the "-%lu" will go outside the boundary due to unconditional sprintf() in use. To make this code more robust, replace two sequential s*printf():s by a single call and then replace forbidden character. It's possible to do this way, because '/' won't ever be in the result of "-%lu". Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8515e4a commit 7afb6d8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

fs/jbd2/journal.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
14911491
{
14921492
journal_t *journal;
14931493
sector_t blocknr;
1494-
char *p;
14951494
int err = 0;
14961495

14971496
blocknr = 0;
@@ -1515,9 +1514,8 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
15151514

15161515
journal->j_inode = inode;
15171516
snprintf(journal->j_devname, sizeof(journal->j_devname),
1518-
"%pg", journal->j_dev);
1519-
p = strreplace(journal->j_devname, '/', '!');
1520-
sprintf(p, "-%lu", journal->j_inode->i_ino);
1517+
"%pg-%lu", journal->j_dev, journal->j_inode->i_ino);
1518+
strreplace(journal->j_devname, '/', '!');
15211519
jbd2_stats_proc_init(journal);
15221520

15231521
return journal;

0 commit comments

Comments
 (0)