Skip to contentSkip to conversation

src/attr_replace_test: limit size of extended attribute value

PATCH Superseded Luis Henriques 3 participants 7 messages May 17, 2019 – May 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src/attr_replace_test: limit size of extended attribute value

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +3 -0
index 0720bfdc18ab..1ca9bf11ba58 100644
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <linux/limits.h>
 
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +45,8 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	if (size > XATTR_SIZE_MAX)
+		size = XATTR_SIZE_MAX;
 	value = malloc(size);
 	if (!value)
 		fail("Failed to allocate memory\n");
#1 lore raw
Quoted 24 lines · Luis Henriques

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +1 -0
index 0720bfdc18ab..1ca9bf11ba58 100644
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <linux/limits.h>
 
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \

src/attr_replace_test.c int main(int argc, char *argv[]) · line 49

Quoted 5 lines
src/attr_replace_test.c +2 -0
@@ -44,6 +45,8 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	if (size > XATTR_SIZE_MAX)
+		size = XATTR_SIZE_MAX;

nit: size = max(size, XATTRS_SIZE_MAX);

Quoted 4 lines
src/attr_replace_test.c +0 -0
 	value = malloc(size);
 	if (!value)
 		fail("Failed to allocate memory\n");
#2 lore raw
Quoted 22 lines · Nikolay Borisov
Quoted 21 lines · Luis Henriques

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +1 -0
index 0720bfdc18ab..1ca9bf11ba58 100644
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <linux/limits.h>
 
Quoted 10 lines

src/attr_replace_test.c int main(int argc, char *argv[]) · line 49

Quoted 8 lines
src/attr_replace_test.c +2 -0
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +45,8 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	if (size > XATTR_SIZE_MAX)
+		size = XATTR_SIZE_MAX;

nit: size = max(size, XATTRS_SIZE_MAX);

Thanks, Nikolay. But I can't find the definition of such macro or function. I believe it's only available in kernel, right? Also, you probably meant min() ;-)

Cheers,

Signature · 1 line
Luis
#3 lore raw
Quoted 35 lines · Luis Henriques
Quoted 22 lines · Nikolay Borisov
Quoted 21 lines · Luis Henriques

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +1 -0
index 0720bfdc18ab..1ca9bf11ba58 100644
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <linux/limits.h>
 
Quoted 10 lines

src/attr_replace_test.c int main(int argc, char *argv[]) · line 49

Quoted 8 lines
src/attr_replace_test.c +2 -0
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +45,8 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	if (size > XATTR_SIZE_MAX)
+		size = XATTR_SIZE_MAX;

nit: size = max(size, XATTRS_SIZE_MAX);

Quoted 3 lines

Thanks, Nikolay. But I can't find the definition of such macro or function. I believe it's only available in kernel, right? Also, you probably meant min() ;-)

Yeah, re min, but it seems there is a MIN/MAX macros provided in <sys/param.h>. Anyway, as mentioned initially this is a minor point :) .

Quoted 3 lines

Cheers,

#4 lore raw

PATCH v2 1/1 src/attr_replace_test: limit size of extended attribute value

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +3 -0
index 0720bfdc18ab..cca8dcf8ff60 100644
@@ -9,6 +9,8 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <sys/param.h>
+#include <linux/limits.h>
 
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +46,7 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	size = MIN(size, XATTR_SIZE_MAX);
 	value = malloc(size);
 	if (!value)
 		fail("Failed to allocate memory\n");
Reviewed-by on v2 1/1
#5 lore raw
Quoted 7 lines · Luis Henriques

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

Looks ok,

--D

Quoted 25 lines
---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +3 -0
index 0720bfdc18ab..cca8dcf8ff60 100644
@@ -9,6 +9,8 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <sys/param.h>
+#include <linux/limits.h>
 
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +46,7 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	size = MIN(size, XATTR_SIZE_MAX);
 	value = malloc(size);
 	if (!value)
 		fail("Failed to allocate memory\n");
Reviewed-by on v1 1/1
#6 lore raw
In reply to Luis Henriques
Quoted 24 lines · Luis Henriques

The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.

---
 src/attr_replace_test.c | 3 +++
 1 file changed, 3 insertions(+)
src/attr_replace_test.c +1 -0
index 0720bfdc18ab..1ca9bf11ba58 100644
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <sys/stat.h>
+#include <linux/limits.h>
 
 #define die() do { perror(""); \
 fprintf(stderr, "error at line %d\n", __LINE__); \

src/attr_replace_test.c int main(int argc, char *argv[]) · line 49

Quoted 5 lines
src/attr_replace_test.c +2 -0
@@ -44,6 +45,8 @@ int main(int argc, char *argv[])
 	size = sbuf.st_blksize * 3 / 4;
 	if (!size)
 		fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+	if (size > XATTR_SIZE_MAX)
+		size = XATTR_SIZE_MAX;

Looks good to me (this or the min()/MIN()/whatever version),

--D

Quoted 3 lines
src/attr_replace_test.c +0 -0
 	value = malloc(size);
 	if (!value)
 		fail("Failed to allocate memory\n");