Skip to contentSkip to conversation

xfs_logprint: Fix buffer overflow printing quotaoff

PATCH Superseded Carlos Maiolino 3 participants 6 messages Mar 16, 2021 – Mar 23, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 logprint/log_print_all.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
logprint/log_print_all.c +6 -6
index 20f2a445..03a32331 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 QUOTA");
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
-		strcat(str, "GROUP QUOTA");
+		printf(" GROUP QUOTA");
 	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 QUOTA");
+	printf("\n");
 }
 
 STATIC void
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 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)

Fix this by removing the static buffer and using printf() directly to print each flag.

Yeah, that makes sense. Not sure why it was using a static buffer, unless I was missing something?

Quoted 1 line

Also add a trailling space before each flag, so they

"trailing space before?" :) I can fix that up on commit.

Quoted 13 lines

are a bit more readable on the output.

---
 logprint/log_print_all.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
logprint/log_print_all.c +0 -0
index 20f2a445..03a32331 100644

logprint/log_print_all.c xlog_recover_print_quotaoff( · line 193

Quoted 9 lines
logprint/log_print_all.c +2 -1
@@ -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);

Ok, we printed this unconditionally before, anyway.

logprint/log_print_all.c xlog_recover_print_quotaoff( · line 199

Quoted 11 lines
logprint/log_print_all.c +3 -5
 	if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
-		strcat(str, "USER QUOTA");
+		printf(" USER QUOTA");
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
-		strcat(str, "GROUP QUOTA");
+		printf(" GROUP QUOTA");
 	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 QUOTA");

Seems like a clean solution, thanks.

Quoted 5 lines
logprint/log_print_all.c +1 -0
+	printf("\n");
 }
 
 STATIC void
#2 lore raw
Quoted 13 lines · Eric Sandeen
Quoted 11 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)

Fix this by removing the static buffer and using printf() directly to print each flag.

Quoted 6 lines

Yeah, that makes sense. Not sure why it was using a static buffer, unless I was missing something?

Quoted 1 line

Also add a trailling space before each flag, so they

"trailing space before?" :) I can fix that up on commit.

Maybe I slipped into my words here... The current printed format, did something like this:

type: USER QUOTAGROUP QUOTAPROJECT QUOTA

I just added a space before each flag string, to print like this:

type: USER QUOTA GROUP QUOTA PROJECT QUOTA

Quoted 3 lines

logprint/log_print_all.c xlog_recover_print_quotaoff( · line 195

Quoted 3 lines
logprint/log_print_all.c +1 -1
 	if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
-		strcat(str, "USER QUOTA");
+		printf(" USER QUOTA");

^ here (an in the remaining ones)

Quoted 19 lines

logprint/log_print_all.c xlog_recover_print_quotaoff( · line 199

Quoted 8 lines
logprint/log_print_all.c +2 -4
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
-		strcat(str, "GROUP QUOTA");
+		printf(" GROUP QUOTA");
 	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 QUOTA");

Seems like a clean solution, thanks.

Quoted 5 lines
logprint/log_print_all.c +1 -0
+	printf("\n");
 }
 
 STATIC void
Signature · 1 line
Carlos
#3 lore raw
Quoted 21 lines · Carlos Maiolino
Quoted 13 lines · Eric Sandeen
Quoted 11 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)

Fix this by removing the static buffer and using printf() directly to print each flag.

Quoted 6 lines

Yeah, that makes sense. Not sure why it was using a static buffer, unless I was missing something?

Quoted 1 line

Also add a trailling space before each flag, so they

"trailing space before?" :) I can fix that up on commit.

Quoted 8 lines

Maybe I slipped into my words here... The current printed format, did something like this:

type: USER QUOTAGROUP QUOTAPROJECT QUOTA

I just added a space before each flag string, to print like this:

type: USER QUOTA GROUP QUOTA PROJECT QUOTA

Any reason we can't just shorten this to "type: USER GROUP PUOTA" ?

--D

Quoted 30 lines
Quoted 5 lines

logprint/log_print_all.c xlog_recover_print_quotaoff( · line 195

Quoted 5 lines
logprint/log_print_all.c +1 -1
 	if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
-		strcat(str, "USER QUOTA");
+		printf(" USER QUOTA");

^ here (an in the remaining ones)

Quoted 19 lines

logprint/log_print_all.c xlog_recover_print_quotaoff( · line 199

Quoted 8 lines
logprint/log_print_all.c +2 -4
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
-		strcat(str, "GROUP QUOTA");
+		printf(" GROUP QUOTA");
 	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 QUOTA");

Seems like a clean solution, thanks.

Quoted 5 lines
logprint/log_print_all.c +1 -0
+	printf("\n");
 }
 
 STATIC void
Signature · 1 line
Carlos
#4 lore raw
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Carlos Maiolino
Quoted 13 lines · Eric Sandeen
Quoted 11 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)

Fix this by removing the static buffer and using printf() directly to print each flag.

Quoted 6 lines

Yeah, that makes sense. Not sure why it was using a static buffer, unless I was missing something?

Quoted 1 line

Also add a trailling space before each flag, so they

"trailing space before?" :) I can fix that up on commit.

Maybe I slipped into my words here... The current printed format, did something like this:

Quoted 7 lines
Quoted 5 lines

type: USER QUOTAGROUP QUOTAPROJECT QUOTA

I just added a space before each flag string, to print like this:

type: USER QUOTA GROUP QUOTA PROJECT QUOTA

Any reason we can't just shorten this to "type: USER GROUP PUOTA" ?

oh yeah, that's a good idea, but: "USER GROUP PROJECT"

-Eric

#5 lore raw
Quoted 28 lines · Eric Sandeen
Quoted 27 lines · Darrick J. Wong
Quoted 26 lines · Carlos Maiolino
Quoted 13 lines · Eric Sandeen
Quoted 11 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)

Fix this by removing the static buffer and using printf() directly to print each flag.

Quoted 6 lines

Yeah, that makes sense. Not sure why it was using a static buffer, unless I was missing something?

Quoted 1 line

Also add a trailling space before each flag, so they

"trailing space before?" :) I can fix that up on commit.

Maybe I slipped into my words here... The current printed format, did something like this:

type: USER QUOTAGROUP QUOTAPROJECT QUOTA

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I just added a space before each flag string, to print like this:

type: USER QUOTA GROUP QUOTA PROJECT QUOTA

Any reason we can't just shorten this to "type: USER GROUP PUOTA" ?

oh yeah, that's a good idea, but: "USER GROUP PROJECT"

Sorry late reply, I don't see why not too, I just followed the current convention. I'll submit a V2

Quoted 3 lines

-Eric

Signature · 1 line
Carlos