From 47d8d2fc9c88c95dfcae2c5c06e6eb3b1ce03a92 Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Tue, 22 Sep 2015 18:30:22 +0530 Subject: gfapi: xattr key length check to avoid brick crash Added check to test if xattr key length > max allowed for OS distribution and return: EINVAL if xattr name pointer is NULL or 0 length ENAMETOOLONG if xattr name length > max allowed for distribution Typically the VFS does this in the kernel for us. But since we are bypassing the VFS by providing the libgfapi to talk directly to the brick process, we need to add such checks. Change-Id: I610a8440871200ae4640351902b752777a3ec0c2 BUG: 1263056 Signed-off-by: Milind Changire Reviewed-on: http://review.gluster.org/12207 Tested-by: Gluster Build System Reviewed-by: Niels de Vos Tested-by: NetBSD Build System --- libglusterfs/src/compat.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h index 458a751c2f4..183002e588e 100644 --- a/libglusterfs/src/compat.h +++ b/libglusterfs/src/compat.h @@ -39,6 +39,7 @@ #ifndef _PATH_UMOUNT #define _PATH_UMOUNT "/bin/umount" #endif +#define GF_XATTR_NAME_MAX XATTR_NAME_MAX #endif /* GF_LINUX_HOST_OS */ #ifdef HAVE_XATTR_H @@ -75,6 +76,7 @@ #ifdef GF_DARWIN_HOST_OS #include #include +#include #define htobe16(x) OSSwapHostToBigInt16(x) #define htole16(x) OSSwapHostToLittleInt16(x) @@ -127,8 +129,18 @@ enum { #ifdef __FreeBSD__ #undef ino_t #define ino_t uint64_t +#include +#include +/* Using NAME_MAX since EXTATTR_MAXNAMELEN is inside a preprocessor conditional + * for the kernel + */ +#define GF_XATTR_NAME_MAX NAME_MAX #endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +#define GF_XATTR_NAME_MAX XATTR_NAME_MAX +#endif + #ifndef ino64_t #define ino64_t ino_t #endif @@ -477,4 +489,8 @@ int gf_mkostemp (char *tmpl, int suffixlen, int flags); int gf_umount_lazy(char *xlname, char *path, int rmdir); +#ifndef GF_XATTR_NAME_MAX +#error 'Please define GF_XATTR_NAME_MAX for your OS distribution.' +#endif + #endif /* __COMPAT_H__ */ -- cgit