Skip to contentSkip to conversation

xfs_logprint: Fix buffer overflow printing quotaoff

PATCH In review Carlos Maiolino 2 participants 2 messages Mar 23, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs_logprint: Fix buffer overflow printing quotaoff

xlog_recover_print_quotaoff() was using a static buffer to aggregate quota option strings to be printed at the end. The buffer size was miscalculated and when printing all 3 flags, a buffer overflow occurs crashing xfs_logprint, like:

QOFF: cnt:1 total:1 a:0x560530ff3bb0 len:160
*** buffer overflow detected ***: terminated
Aborted (core dumped)

Fix this by removing the static buffer and using printf() directly to print each flag. Also add a trailling space before each flag, so they are a bit more readable on the output.

---
Changelog:

- V2:
Update strings removing the "QUOTA" of each printf, resulting
in: "USER GROUP PROJECT"

 logprint/log_print_all.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
logprint/log_print_all.c +6 -6
index 20f2a445..c9c453f6 100644
@@ -186,18 +186,18 @@ xlog_recover_print_quotaoff(
 	struct xlog_recover_item *item)
 {
 	xfs_qoff_logformat_t	*qoff_f;
-	char			str[32] = { 0 };
 
 	qoff_f = (xfs_qoff_logformat_t *)item->ri_buf[0].i_addr;
+
 	ASSERT(qoff_f);
+	printf(_("\tQUOTAOFF: #regs:%d   type:"), qoff_f->qf_size);
 	if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
-		strcat(str, "USER QUOTA");
+		printf(" USER");
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
-		strcat(str, "GROUP QUOTA");
+		printf(" GROUP");
 	if (qoff_f->qf_flags & XFS_PQUOTA_ACCT)
-		strcat(str, "PROJECT QUOTA");
-	printf(_("\tQUOTAOFF: #regs:%d   type:%s\n"),
-	       qoff_f->qf_size, str);
+		printf(" PROJECT");
+	printf("\n");
 }
 
 STATIC void
Signature · 1 line
2.29.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Carlos Maiolino

xlog_recover_print_quotaoff() was using a static buffer to aggregate quota option strings to be printed at the end. The buffer size was miscalculated and when printing all 3 flags, a buffer overflow occurs crashing xfs_logprint, like:

QOFF: cnt:1 total:1 a:0x560530ff3bb0 len:160
*** buffer overflow detected ***: terminated
Aborted (core dumped)

Quoted 6 lines

Fix this by removing the static buffer and using printf() directly to print each flag. Also add a trailling space before each flag, so they are a bit more readable on the output.

Seems reasonable to me,

--D

Quoted 42 lines

---
Changelog:

- V2:
Update strings removing the "QUOTA" of each printf, resulting
in: "USER GROUP PROJECT"

 logprint/log_print_all.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
logprint/log_print_all.c +6 -6
index 20f2a445..c9c453f6 100644
@@ -186,18 +186,18 @@ xlog_recover_print_quotaoff(
 	struct xlog_recover_item *item)
 {
 	xfs_qoff_logformat_t	*qoff_f;
-	char			str[32] = { 0 };
 
 	qoff_f = (xfs_qoff_logformat_t *)item->ri_buf[0].i_addr;
+
 	ASSERT(qoff_f);
+	printf(_("\tQUOTAOFF: #regs:%d   type:"), qoff_f->qf_size);
 	if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
-		strcat(str, "USER QUOTA");
+		printf(" USER");
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
-		strcat(str, "GROUP QUOTA");
+		printf(" GROUP");
 	if (qoff_f->qf_flags & XFS_PQUOTA_ACCT)
-		strcat(str, "PROJECT QUOTA");
-	printf(_("\tQUOTAOFF: #regs:%d   type:%s\n"),
-	       qoff_f->qf_size, str);
+		printf(" PROJECT");
+	printf("\n");
 }
 
 STATIC void
Signature · 1 line
2.29.2