From: Hin-Tak Leung Subject: Re: [PATCH RFC V1] hfsplus: Correct usage of HFSPLUS_ATTR_MAX_STRLEN for non-English attributes Date: Sun, 13 Apr 2014 01:52:05 +0100 (BST) Message-ID: <1397350325.32614.YahooMailBasic@web172304.mail.ir2.yahoo.com> Reply-To: htl10@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-fsdevel@vger.kernel.org To: aia21@cam.ac.uk Return-path: Received: from nm31-vm8.bullet.mail.ir2.yahoo.com ([212.82.97.95]:24085 "EHLO nm31-vm8.bullet.mail.ir2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750810AbaDMAwI convert rfc822-to-8bit (ORCPT ); Sat, 12 Apr 2014 20:52:08 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Hi Anton, Thanks again for a rather thoughtful review. I do completely agree, that the bound checks are almost completely usel= ess before and after - before the change they were simply wrong, after the change they are simply doi= ng twice the work, just earlier. There is no need to do twice the work - if hfsplus_asc2uni() works corr= ectly, and failures are caught properly, there is no need to try() it first. So that's why I simply removed the = one in hfsplus_attr_build_key(),since the check happens immediately before the actual call. It is definitely = stupid doing a try() then immediately the real thing. But there is one advantage of doing it early - assuming try() is cheap = (may or may not be the case): the real hfsplus_asc2uni() is buried quite a lot further after setting = up the atttribute B-tree for searches, etc. So by the time the actual call happens, throwing away al= l that work B-tree find_init, etc might be wasteful; besides that stuff also have mutex lo= cks around it, etc, so unwinding and catch errors there may not be as easy. =20 In principle, I agree that if any error from hfsplus_asc2uni() is check= ed and caught, there is no need to do a try() first; the practical dificulty is just that th= e real hfsplus_asc2uni() is buried rather deep, and within at least one mutex = lock. So I did think about the first approach you suggested, just thought it = is much harder - the current patch is just too boring and not doing anything risky, so= it is safe to use. I think the 2nd approach (keeping the try() result) would get around my worry about= that mutex lock, so I may look into that. Now I have an "tedious, slow but working correctly how it should be" pa= tch, for reference, and it is a good thing to have. - it is quite educational to try to use all= 127 unicode character limit of the attribute - and not possible to do that in a UTF-8 locale.= Both the userland tools (xttr) and many of the other file systems have a 255 byte limit for EA's (in n= ls, and 127 unicode char can be as bad as 127 x 3 =3D 381 in UTF-8). I had to use a= n explicit nls=3D mount option and run my terminal/content at a different encoding to ful= ly use that 127 unit storage. When a Mac user had already written an unusually long attribute, and we= try to read it under linux - it currently (without this patch) gives a scary I= /O error. That's really not good. i have thought of a genuine (mis-) use of non-english attributes. All t= he english alphabets have their "half/full-width" equivalent at a higher code point. ( http://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_form= s ). It is entirely possible for a japanese person to be typing what he thou= ght is english, and looks like english, and read like english - only stretc= hed out or shrunk - but not actually ascii. I''ll have a go at ripping all the useless bound checks out, and see how painful it gets. Hin-Tak ------------------------------ On Sun, Apr 13, 2014 12:01 AM BST Anton Altaparmakov wrote: >Hi Hin-Tak, > >I think you are taking a sub-optimal approach!=A0 Think about it: you = are now performing the hfsplus_asc2uni() twice for each name being hand= led!=A0 Once to check if the length is ok and once to get the actual re= sult.=A0 This is a waste of time. > >Instead, just do the conversion.=A0 If the name is longer than allowed= , hfsplus_asc2uni() will return -ENAMETOOLONG and at that point you can= bail out.=A0 There is no need to do a "test conversion" first the resu= lt of which you through away (and even worse you do a kmalloc() twice -= once for the "test" and once for the real thing)... > >In fact you do it correctly in your proposed patch in hfsplus_attr_bui= ld_key(): You thrown out the length check and replace it with a call to= hfsplus_asc2uni() that returns -ENAMETOOLONG if the name is too long a= nd thus hfsplus_attr_build_key() returns -ENAMETOOLONG.=A0 All you need= to do is change the code to do the Right Thing when it gets back -ENAM= ETOOLONG and you are done (and you throw away all the bogus length chec= ks in the upper layers). > >If you definitely want to do checking in advance, then that is fine, t= oo - but don't do it with a test conversion - instead, convert it, chec= k the length of the converted string and then use the converted name fr= om there onwards. > >Both my suggestions are perhaps more involved changes than what you ar= e doing but I think they are much more worthwhile as they do not introd= uce double the allocations and conversions. > >Best regards, > >=A0=A0=A0 Anton > >On 12 Apr 2014, at 04:26, Hin-Tak Leung wrote= : > >> From: Hin-Tak Leung >>=20 >> HFSPLUS_ATTR_MAX_STRLEN (=3D127) is a limit for the number of unicod= e character >> (UTF-16BE) storable in the HFS+ file system. Almost all the current >> usage of it is wrong in relation to NLS to on-disk conversion. >>=20 >> Except for one use calling hfsplus_asc2uni (which should stay the sa= me) and >> its uses in calling hfsplus_uni2asc (which was changed in an earlier= patch), >> all the other uses are of the forms: >>=20 >> - char buffer[size] >>=20 >> - bound check: "if (input_length > size) return failure;" >>=20 >> Conversion between on-disk and NLS char strings (in whichever direct= ion) >> always needs to be in the worst, so all char buffers of that size >> need to have a NLS_MAX_CHARSET_SIZE x . >>=20 >> The bound checks are all wrong, since they all compare >> nls_length to unicode_length_limit. >>=20 >> A new function, hfsplus_try_asc2uni(), is introduced to >> try the conversion, to do the bound-check instead. (After review thi= s >> will be splitted off as a separate earlier patch). >>=20 >> Before this patch, trying to set a 55 CJK character (in a UTF-8 loca= le) >> + user prefix fails with: >>=20 >>=A0 =A0 $ setfattr -n user.`cat testing-string` -v `cat testing-strin= g` testing-string >>=A0 =A0 setfattr: testing-string: Operation not supported >>=20 >> and getting long attributes is particular ugly(!): >>=20 >>=A0 =A0 find /mnt/* -type f -exec getfattr -d {} \; >>=A0 =A0 getfattr: /mnt/testing-string: Input/output error >>=20 >> with console log: >>=A0 =A0 [268008.389781] hfsplus: unicode conversion failed >>=20 >> After the patch, both of the above works. >>=20 >> However, I was not able to set double the size (110 + 5 is still und= er 127): >>=20 >>=A0 =A0 $setfattr -n user.`cat testing-string testing-string` -v `cat= testing-string testing-string` testing-string >>=A0 =A0 setfattr: testing-string: Numerical result out of range >>=20 >> But this also fails on ext2, so this failure is not HFS+ specific. I= t seems >> that either the command line or the system call itself has a 256-byt= e limit. >> (110 CJK char in UTF-8 is 330 bytes). >>=20 >> Signed-off-by: Hin-Tak Leung >> --- >> fs/hfsplus/attributes.c=A0 =A0=A0=A0| 11 ++++----- >> fs/hfsplus/hfsplus_fs.h=A0 =A0=A0=A0|=A0 7 ++++++ >> fs/hfsplus/unicode.c=A0 =A0 =A0 =A0 | 18 +++++++++++++++ >> fs/hfsplus/xattr.c=A0 =A0 =A0 =A0 =A0 | 40 ++++++++++++++++++++++---= ------- >> fs/hfsplus/xattr_security.c | 56 ++++++++++++++++++++++++++++++-----= ---------- >> fs/hfsplus/xattr_trusted.c=A0 | 36 +++++++++++++++++++++-------- >> fs/hfsplus/xattr_user.c=A0 =A0=A0=A0| 36 +++++++++++++++++++++------= -- >> 7 files changed, 147 insertions(+), 57 deletions(-) >>=20 >> diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c >> index caf89a7..f3345c0 100644 >> --- a/fs/hfsplus/attributes.c >> +++ b/fs/hfsplus/attributes.c >> @@ -54,14 +54,11 @@ int hfsplus_attr_build_key(struct super_block *s= b, hfsplus_btree_key *key, >> =A0=A0=A0 memset(key, 0, sizeof(struct hfsplus_attr_key)); >> =A0=A0=A0 key->attr.cnid =3D cpu_to_be32(cnid); >> =A0=A0=A0 if (name) { >> -=A0=A0=A0 =A0=A0=A0 len =3D strlen(name); >> -=A0=A0=A0 =A0=A0=A0 if (len > HFSPLUS_ATTR_MAX_STRLEN) { >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 pr_err("invalid xattr name's length\n= "); >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return -EINVAL; >> -=A0=A0=A0 =A0=A0=A0 } >> -=A0=A0=A0 =A0=A0=A0 hfsplus_asc2uni(sb, >> +=A0=A0=A0 =A0=A0=A0 int res =3D hfsplus_asc2uni(sb, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 (struct hfsplus_unistr *)&ke= y->attr.key_name, >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN, na= me, len); >> +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN, na= me, strlen(name)); >> +=A0=A0=A0 =A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return res; >> =A0=A0=A0 =A0=A0=A0 len =3D be16_to_cpu(key->attr.key_name.length); >> =A0=A0=A0 } else { >> =A0=A0=A0 =A0=A0=A0 key->attr.key_name.length =3D 0; >> diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h >> index 83dc292..80257d0 100644 >> --- a/fs/hfsplus/hfsplus_fs.h >> +++ b/fs/hfsplus/hfsplus_fs.h >> @@ -507,6 +507,13 @@ int hfsplus_uni2asc(struct super_block *, >> =A0=A0=A0 =A0=A0=A0 const struct hfsplus_unistr *, char *, int *); >> int hfsplus_asc2uni(struct super_block *, >> =A0=A0=A0 =A0=A0=A0 struct hfsplus_unistr *, int, const char *, int)= ; >> +int hfsplus_try_asc2uni_sb(struct super_block *sb, >> +=A0=A0=A0 =A0=A0=A0 const char *nls_name, int unilimit); >> +static inline int hfsplus_try_asc2uni(const struct dentry *dentry, >> +=A0=A0=A0 =A0=A0=A0 const char *nls_name, int unilimit) >> +{ >> +=A0=A0=A0 return hfsplus_try_asc2uni_sb(dentry->d_sb, nls_name, uni= limit); >> +} >> int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *st= r); >> int hfsplus_compare_dentry(const struct dentry *parent, const struct= dentry *dentry, >> =A0=A0=A0 =A0=A0=A0 unsigned int len, const char *str, const struct = qstr *name); >> diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c >> index e8ef121..cd00bd2 100644 >> --- a/fs/hfsplus/unicode.c >> +++ b/fs/hfsplus/unicode.c >> @@ -330,6 +330,24 @@ int hfsplus_asc2uni(struct super_block *sb, >> } >>=20 >> /* >> + * Try encoding an nls_name within a unicode size limit, >> + * and see whether it will fit. >> + */ >> +int hfsplus_try_asc2uni_sb(struct super_block *sb, >> +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 const char *nls_name, int unilimit) >> +{ >> +=A0=A0=A0 int res =3D 0; >> +=A0=A0=A0 struct hfsplus_unistr *ustr =3D kmalloc(sizeof(*ustr), GF= P_KERNEL); >> +=A0=A0=A0 if (!ustr) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> + >> +=A0=A0=A0 res =3D hfsplus_asc2uni(sb, >> +=A0=A0=A0 =A0=A0=A0 ustr, unilimit, nls_name, strlen(nls_name)); >> +=A0=A0=A0 kfree(ustr); >> +=A0=A0=A0 return res; >> +} >> + >> +/* >>=A0 * Hash a string to an integer as appropriate for the HFS+ filesys= tem. >>=A0 * Composed unicode characters are decomposed and case-folding is = performed >>=A0 * if the appropriate bits are (un)set on the superblock. >> diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c >> index 40c0a63..a05cab9 100644 >> --- a/fs/hfsplus/xattr.c >> +++ b/fs/hfsplus/xattr.c >> @@ -805,15 +805,15 @@ end_removexattr: >> static int hfsplus_osx_getxattr(struct dentry *dentry, const char *n= ame, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 void *buffer, size= _t size, int type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 XATTR_MAC_OSX_PREFIX_LEN + = 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len > HFSPLUS_ATTR_MAX_STRLEN) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, HFSPLUS_ATTR_MA= X_STRLEN); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> =A0=A0=A0 /* >> =A0=A0=A0=A0=A0* Don't allow retrieving properly prefixed attributes >> @@ -821,22 +821,30 @@ static int hfsplus_osx_getxattr(struct dentry = *dentry, const char *name, >> =A0=A0=A0=A0=A0*/ >> =A0=A0=A0 if (is_known_namespace(name)) >> =A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN >> +=A0=A0=A0 =A0=A0=A0 + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> +=A0=A0=A0 strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); >> +=A0=A0=A0 strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_getxattr(dentry, xattr_name, buffer, size)= ; >> +=A0=A0=A0 res =3D hfsplus_getxattr(dentry, xattr_name, buffer, size= ); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static int hfsplus_osx_setxattr(struct dentry *dentry, const char *n= ame, >> =A0=A0=A0 =A0=A0=A0 const void *buffer, size_t size, int flags, int = type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 XATTR_MAC_OSX_PREFIX_LEN + = 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len > HFSPLUS_ATTR_MAX_STRLEN) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, HFSPLUS_ATTR_MA= X_STRLEN); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> =A0=A0=A0 /* >> =A0=A0=A0=A0=A0* Don't allow setting properly prefixed attributes >> @@ -844,8 +852,16 @@ static int hfsplus_osx_setxattr(struct dentry *= dentry, const char *name, >> =A0=A0=A0=A0=A0*/ >> =A0=A0=A0 if (is_known_namespace(name)) >> =A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN >> +=A0=A0=A0 =A0=A0=A0 + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> +=A0=A0=A0 strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); >> +=A0=A0=A0 strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_setxattr(dentry, xattr_name, buffer, size,= flags); >> +=A0=A0=A0 res =3D hfsplus_setxattr(dentry, xattr_name, buffer, size= , flags); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *lis= t, >> diff --git a/fs/hfsplus/xattr_security.c b/fs/hfsplus/xattr_security= =2Ec >> index 0072276..f4993e0 100644 >> --- a/fs/hfsplus/xattr_security.c >> +++ b/fs/hfsplus/xattr_security.c >> @@ -14,37 +14,53 @@ >> static int hfsplus_security_getxattr(struct dentry *dentry, const ch= ar *name, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 void *buffer, size= _t size, int type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_ST= RLEN) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, >> +=A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_SECURITY_PREFIX= _LEN); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 strcpy(xattr_name, XATTR_SECURITY_PREFIX); >> =A0=A0=A0 strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_getxattr(dentry, xattr_name, buffer, size)= ; >> +=A0=A0=A0 res =3D hfsplus_getxattr(dentry, xattr_name, buffer, size= ); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static int hfsplus_security_setxattr(struct dentry *dentry, const ch= ar *name, >> =A0=A0=A0 =A0=A0=A0 const void *buffer, size_t size, int flags, int = type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_ST= RLEN) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, >> +=A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_SECURITY_PREFIX= _LEN); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 strcpy(xattr_name, XATTR_SECURITY_PREFIX); >> =A0=A0=A0 strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_setxattr(dentry, xattr_name, buffer, size,= flags); >> +=A0=A0=A0 res =3D hfsplus_setxattr(dentry, xattr_name, buffer, size= , flags); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static size_t hfsplus_security_listxattr(struct dentry *dentry, char= *list, >> @@ -62,31 +78,35 @@ static int hfsplus_initxattrs(struct inode *inod= e, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 void *fs_info) >> { >> =A0=A0=A0 const struct xattr *xattr; >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t xattr_name_len; >> +=A0=A0=A0 char *xattr_name; >> =A0=A0=A0 int err =3D 0; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 for (xattr =3D xattr_array; xattr->name !=3D NULL; xattr++= ) { >> -=A0=A0=A0 =A0=A0=A0 xattr_name_len =3D strlen(xattr->name); >>=20 >> -=A0=A0=A0 =A0=A0=A0 if (xattr_name_len =3D=3D 0) >> +=A0=A0=A0 =A0=A0=A0 if (!strcmp(xattr->name, ")) >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 continue; >>=20 >> -=A0=A0=A0 =A0=A0=A0 if (xattr_name_len + XATTR_SECURITY_PREFIX_LEN = > >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN) >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 =A0=A0=A0 err =3D hfsplus_try_asc2uni_sb(inode->i_sb, xat= tr->name, >> +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_SECUR= ITY_PREFIX_LEN); >> +=A0=A0=A0 =A0=A0=A0 if (err) >> +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 break; >>=20 >> =A0=A0=A0 =A0=A0=A0 strcpy(xattr_name, XATTR_SECURITY_PREFIX); >> =A0=A0=A0 =A0=A0=A0 strcpy(xattr_name + >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 XATTR_SECURITY_PREFIX_LEN, xattr->name= ); >> =A0=A0=A0 =A0=A0=A0 memset(xattr_name + >> -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 XATTR_SECURITY_PREFIX_LEN + xattr_nam= e_len, 0, 1); >> +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 XATTR_SECURITY_PREFIX_LEN + strlen(xa= ttr->name), 0, 1); >>=20 >> =A0=A0=A0 =A0=A0=A0 err =3D __hfsplus_setxattr(inode, xattr_name, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 xattr->value, xatt= r->value_len, 0); >> =A0=A0=A0 =A0=A0=A0 if (err) >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 break; >> =A0=A0=A0 } >> +=A0=A0=A0 kfree(xattr_name); >> =A0=A0=A0 return err; >> } >>=20 >> diff --git a/fs/hfsplus/xattr_trusted.c b/fs/hfsplus/xattr_trusted.c >> index 426cee2..36716af 100644 >> --- a/fs/hfsplus/xattr_trusted.c >> +++ b/fs/hfsplus/xattr_trusted.c >> @@ -12,37 +12,53 @@ >> static int hfsplus_trusted_getxattr(struct dentry *dentry, const cha= r *name, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 void *buffer, size= _t size, int type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len + XATTR_TRUSTED_PREFIX_LEN > HFSPLUS_ATTR_MAX_STR= LEN) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, >> +=A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_TRUSTED_PREFIX_= LEN); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 strcpy(xattr_name, XATTR_TRUSTED_PREFIX); >> =A0=A0=A0 strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_getxattr(dentry, xattr_name, buffer, size)= ; >> +=A0=A0=A0 res =3D hfsplus_getxattr(dentry, xattr_name, buffer, size= ); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static int hfsplus_trusted_setxattr(struct dentry *dentry, const cha= r *name, >> =A0=A0=A0 =A0=A0=A0 const void *buffer, size_t size, int flags, int = type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len + XATTR_TRUSTED_PREFIX_LEN > HFSPLUS_ATTR_MAX_STR= LEN) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, >> +=A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_TRUSTED_PREFIX_= LEN); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 strcpy(xattr_name, XATTR_TRUSTED_PREFIX); >> =A0=A0=A0 strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_setxattr(dentry, xattr_name, buffer, size,= flags); >> +=A0=A0=A0 res =3D hfsplus_setxattr(dentry, xattr_name, buffer, size= , flags); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char = *list, >> diff --git a/fs/hfsplus/xattr_user.c b/fs/hfsplus/xattr_user.c >> index e340165..26b832c 100644 >> --- a/fs/hfsplus/xattr_user.c >> +++ b/fs/hfsplus/xattr_user.c >> @@ -12,37 +12,53 @@ >> static int hfsplus_user_getxattr(struct dentry *dentry, const char *= name, >> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 void *buffer, size= _t size, int type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len + XATTR_USER_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN= ) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, >> +=A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_USER_PREFIX_LEN= ); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 strcpy(xattr_name, XATTR_USER_PREFIX); >> =A0=A0=A0 strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_getxattr(dentry, xattr_name, buffer, size)= ; >> +=A0=A0=A0 res =3D hfsplus_getxattr(dentry, xattr_name, buffer, size= ); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static int hfsplus_user_setxattr(struct dentry *dentry, const char *= name, >> =A0=A0=A0 =A0=A0=A0 const void *buffer, size_t size, int flags, int = type) >> { >> -=A0=A0=A0 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] =3D {0}; >> -=A0=A0=A0 size_t len =3D strlen(name); >> +=A0=A0=A0 char *xattr_name; >> +=A0=A0=A0 int res; >>=20 >> =A0=A0=A0 if (!strcmp(name, ")) >> =A0=A0=A0 =A0=A0=A0 return -EINVAL; >>=20 >> -=A0=A0=A0 if (len + XATTR_USER_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN= ) >> -=A0=A0=A0 =A0=A0=A0 return -EOPNOTSUPP; >> +=A0=A0=A0 res =3D hfsplus_try_asc2uni(dentry, name, >> +=A0=A0=A0 =A0=A0=A0 HFSPLUS_ATTR_MAX_STRLEN - XATTR_USER_PREFIX_LEN= ); >> +=A0=A0=A0 if (res) >> +=A0=A0=A0 =A0=A0=A0 return res; >>=20 >> +=A0=A0=A0 xattr_name =3D kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATT= R_MAX_STRLEN + 1, >> +=A0=A0=A0 =A0=A0=A0 GFP_KERNEL); >> +=A0=A0=A0 if (!xattr_name) >> +=A0=A0=A0 =A0=A0=A0 return -ENOMEM; >> =A0=A0=A0 strcpy(xattr_name, XATTR_USER_PREFIX); >> =A0=A0=A0 strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); >>=20 >> -=A0=A0=A0 return hfsplus_setxattr(dentry, xattr_name, buffer, size,= flags); >> +=A0=A0=A0 res =3D hfsplus_setxattr(dentry, xattr_name, buffer, size= , flags); >> +=A0=A0=A0 kfree(xattr_name); >> +=A0=A0=A0 return res; >> } >>=20 >> static size_t hfsplus_user_listxattr(struct dentry *dentry, char *li= st, >> --=20 >> 1.9.0 >>=20 >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-fsde= vel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at=A0 http://vger.kernel.org/majordomo-info.html > >Best regards, > >=A0=A0=A0 Anton >--=20 >Anton Altaparmakov (replace at with @) >Unix Support, Computing Service, University of Cambridge >J.J. Thomson Avenue, Cambridge, CB3 0RB, UK > -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html