Skip to contentSkip to conversation

tests/filesystem: fix quotas_test

PATCH In review Stephen Smalley 2 participants 3 messages May 11, 2020 – May 13, 2020 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v2 1/1 tests/filesystem: fix quotas_test

As per the man page, quotactl(2) expects to be passed a pointer to a 4-byte buffer for Q_GETFMT. The kernel copies a single u32 value. On Ubuntu, this was detected as a stack smash when running the test. Fix the test program.

---
v2 includes stdint.h and uses uint32_t for the fmtval variable.

 tests/filesystem/quotas_test.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tests/filesystem/quotas_test.c +6 -5
index 8359811..bca230d 100644
@@ -1,3 +1,4 @@
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -33,7 +34,7 @@ int main(int argc, char *argv[])
 	int opt, result, qcmd, save_err, test_id = geteuid();
 	char *context, *src = NULL, *tgt = NULL;
 	bool verbose = false;
-	char fmt_buf[2];
+	uint32_t fmtval;
 
 	while ((opt = getopt(argc, argv, "s:t:v")) != -1) {
 		switch (opt) {
@@ -77,7 +78,7 @@ int main(int argc, char *argv[])
 			printf("User Quota - ON\n");
 
 		qcmd = QCMD(Q_GETFMT, USRQUOTA);
-		result = quotactl(qcmd, src, test_id, fmt_buf);
+		result = quotactl(qcmd, src, test_id, (caddr_t)&fmtval);
 		save_err = errno;
 		if (result < 0) {
 			fprintf(stderr, "quotactl(Q_GETFMT, USRQUOTA) Failed: %s\n",
@@ -85,7 +86,7 @@ int main(int argc, char *argv[])
 			return save_err;
 		}
 		if (verbose)
-			printf("User Format: 0x%x\n", fmt_buf[0]);
+			printf("User Format: 0x%x\n", fmtval);
 
 		qcmd = QCMD(Q_QUOTAOFF, USRQUOTA);
 		result = quotactl(qcmd, src, QFMT_VFS_V0, tgt);
@@ -113,7 +114,7 @@ int main(int argc, char *argv[])
 			printf("Group Quota - ON\n");
 
 		qcmd = QCMD(Q_GETFMT, GRPQUOTA);
-		result = quotactl(qcmd, src, test_id, fmt_buf);
+		result = quotactl(qcmd, src, test_id, (caddr_t)&fmtval);
 		save_err = errno;
 		if (result < 0) {
 			fprintf(stderr, "quotactl(Q_GETFMT, GRPQUOTA) Failed: %s\n",
@@ -121,7 +122,7 @@ int main(int argc, char *argv[])
 			return save_err;
 		}
 		if (verbose)
-			printf("Group Format: 0x%x\n", fmt_buf[0]);
+			printf("Group Format: 0x%x\n", fmtval);
 
 		qcmd = QCMD(Q_QUOTAOFF, GRPQUOTA);
 		result = quotactl(qcmd, src, QFMT_VFS_V0, tgt);
Signature · 1 line
2.23.3
Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · Stephen Smalley

As per the man page, quotactl(2) expects to be passed a pointer to a 4-byte buffer for Q_GETFMT. The kernel copies a single u32 value. On Ubuntu, this was detected as a stack smash when running the test. Fix the test program.

Quoted 63 lines

---
v2 includes stdint.h and uses uint32_t for the fmtval variable.

 tests/filesystem/quotas_test.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tests/filesystem/quotas_test.c +6 -6
index 8359811..bca230d 100644
@@ -1,3 +1,4 @@
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -33,7 +34,7 @@ int main(int argc, char *argv[])
        int opt, result, qcmd, save_err, test_id = geteuid();
        char *context, *src = NULL, *tgt = NULL;
        bool verbose = false;
-       char fmt_buf[2];
+       uint32_t fmtval;
 
        while ((opt = getopt(argc, argv, "s:t:v")) != -1) {
                switch (opt) {
@@ -77,7 +78,7 @@ int main(int argc, char *argv[])
                        printf("User Quota - ON\n");
 
                qcmd = QCMD(Q_GETFMT, USRQUOTA);
-               result = quotactl(qcmd, src, test_id, fmt_buf);
+               result = quotactl(qcmd, src, test_id, (caddr_t)&fmtval);
                save_err = errno;
                if (result < 0) {
                        fprintf(stderr, "quotactl(Q_GETFMT, USRQUOTA) Failed: %s\n",
@@ -85,7 +86,7 @@ int main(int argc, char *argv[])
                        return save_err;
                }
                if (verbose)
-                       printf("User Format: 0x%x\n", fmt_buf[0]);
+                       printf("User Format: 0x%x\n", fmtval);
 
                qcmd = QCMD(Q_QUOTAOFF, USRQUOTA);
                result = quotactl(qcmd, src, QFMT_VFS_V0, tgt);
@@ -113,7 +114,7 @@ int main(int argc, char *argv[])
                        printf("Group Quota - ON\n");
 
                qcmd = QCMD(Q_GETFMT, GRPQUOTA);
-               result = quotactl(qcmd, src, test_id, fmt_buf);
+               result = quotactl(qcmd, src, test_id, (caddr_t)&fmtval);
                save_err = errno;
                if (result < 0) {
                        fprintf(stderr, "quotactl(Q_GETFMT, GRPQUOTA) Failed: %s\n",
@@ -121,7 +122,7 @@ int main(int argc, char *argv[])
                        return save_err;
                }
                if (verbose)
-                       printf("Group Format: 0x%x\n", fmt_buf[0]);
+                       printf("Group Format: 0x%x\n", fmtval);
 
                qcmd = QCMD(Q_QUOTAOFF, GRPQUOTA);
                result = quotactl(qcmd, src, QFMT_VFS_V0, tgt);
--

2.23.3

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#2 lore raw
Quoted 10 lines · Ondrej Mosnacek
Quoted 6 lines · Stephen Smalley

As per the man page, quotactl(2) expects to be passed a pointer to a 4-byte buffer for Q_GETFMT. The kernel copies a single u32 value. On Ubuntu, this was detected as a stack smash when running the test. Fix the test program.

Patch applied.

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.