From: Hin-Tak Leung Subject: the end of the unicode fix journey. Re: [PATCH RFC V1] hfsplus: Correct usage of HFSPLUS_ATTR_MAX_STRLEN for non-English attributes Date: Mon, 14 Apr 2014 02:13:51 +0100 (BST) Message-ID: <1397438031.49854.YahooMailBasic@web172301.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, slava@dubeyko.com Return-path: Received: from nm33-vm1.bullet.mail.ir2.yahoo.com ([212.82.97.106]:44930 "EHLO nm33-vm1.bullet.mail.ir2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770AbaDNBNx convert rfc822-to-8bit (ORCPT ); Sun, 13 Apr 2014 21:13:53 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Hi Anton and Vyacheslav, I think I have reached the end of this unicode fix journey. It turned out that all the bound checks (and all the try_asc2uni() code= ) can be removed. Because there is only one usage asc2uni() as far as attributes are concerned, a= nd that's the one in hfsplus_attr_build_key() which Anton mentioned and which I had corrected. build_key() is used by find_attr()= and also create_attr(), which, as far as I can see, is used by everything else. = And it does make sense that there are only two uses: find an existing attribute (po= ssibly as a precursor to removal) or create a new one. However, I also uncovered a whole bunch of potential problems with wher= e error from asc2uni() in the catalog code is uncaught. So I like to ask you two to help critically check these ideas: - Is it true that all usages of attribute length check eventually lead = to the single one in hfsplus_attr_build_key(), via find/create? - I like to know how to provoke the error in the unpatched catalog code= , for testing purposes. - In general, the error recovery for that whole bunch of potential prob= lems with=20 asc2uni in the catalog code seems obvious - I just make it goto whereve= r neighbouring errors goto, even when I don't completely understand how t= o provoke the error and/or what the error might look like in real usage. There is one particular possible error in the catalog code I am not sur= e about. at the end of hfsplus_create_cat() in catalog.c, after the "err1:" labe= l. If it fails, I just make it by-pass the next statement to go to err2. I think it mak= es sense that way but I'd like another pair of eyes. So it is going to be a series of 4 patches: - hfsplus: fixes worst-case unicode to char conversion of file names an= d attributes (about uni2asc) - Correct usage of HFSPLUS_ATTR_MAX_STRLEN for non-English attributes - remove unused hfsplus_attr_build_key_uni() - fixes error propagation of hfsplus_asc2uni It seems to have come full circle - from checking problems with uni2asc= , to checking problems with hfsplus_asc2uni. The 3rd patch is just unused at= tribute code I=20 think should be removed since I cannot see a future use of it. It seems to be just copied from the catalog code which has wider use. I found it easier to fix by API (essentially, a grep, followed by looki= ng at where they are, and further grep), although, by purpose, these are t= wo areas, names vs attributes, and for back-port purposes one which divide these patches differently. Even by API, the division is not unambiguous, since one use of uni2asc involves incorrect use of HFSPLUS_ATTR_MAX_STRLEN, and one error propagation of hfsplus_asc2uni() is also fixed in correct= ing usage of HFSPLUS_ATTR_MAX_STRLEN. But that's how I like to divide them (i.e. "mostly" by API in a histori= cal context). I think dividing by name vs attributes would not be clearer, even thoug= h for back-porting purpose it would be better that way, for older kernels without attribute support. Patches to follow, after doing some extended write-up of relevant commi= t messages etc. Hin-Tak ------------------------------ On Sun, Apr 13, 2014 1:52 AM BST Hin-Tak Leung wrote: >Hi Anton, > >Thanks again for a rather thoughtful review. > >I do completely agree, that the bound checks are almost completely use= less before and after - before >the change they were simply wrong, after the change they are simply do= ing twice the work, just earlier. > >There is no need to do twice the work - if hfsplus_asc2uni() works cor= rectly, 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 a= ll that work B-tree >find_init, etc might be wasteful; besides that stuff also have mutex l= ocks around it, etc, so >unwinding and catch errors there may not be as easy.=A0=20 > >In principle, I agree that if any error from hfsplus_asc2uni() is chec= ked and caught, there >is no need to do a try() first; the practical dificulty is just that t= he 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, s= o it is safe to use. I think the >2nd approach (keeping the try() result) would get around my worry abou= t that mutex lock, so >I may look into that. > >Now I have an "tedious, slow but working correctly how it should be" p= atch, for reference, and >it is a good thing to have. - it is quite educational to try to use al= l 127 unicode character >limit of the attribute - and not possible to do that in a UTF-8 locale= =2E Both the userland tools (xttr) >and many of the other file systems have a 255 byte limit for EA's (in = nls, and 127 >unicode char can be as bad as 127 x 3 =3D 381 in UTF-8). I had to use = an explicit nls=3D >mount option and run my terminal/content at a different encoding to fu= lly use >that 127 unit storage. > >When a Mac user had already written an unusually long attribute, and w= e 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 = the english >alphabets have their "half/full-width" equivalent at a higher >code point. ( http://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_for= ms ). >It is entirely possible for a japanese person to be typing what he tho= ught >is english, and looks like english, and read like english - only stret= ched 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 han= dled!=A0 Once to check if the length is ok and once to get the actual r= esult.=A0 This is a waste of time. >> >>Instead, just do the conversion.=A0 If the name is longer than allowe= d, hfsplus_asc2uni() will return -ENAMETOOLONG and at that point you ca= n bail out.=A0 There is no need to do a "test conversion" first the res= ult 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_bu= ild_key(): You thrown out the length check and replace it with a call t= o hfsplus_asc2uni() that returns -ENAMETOOLONG if the name is too long = and thus hfsplus_attr_build_key() returns -ENAMETOOLONG.=A0 All you nee= d to do is change the code to do the Right Thing when it gets back -ENA= METOOLONG and you are done (and you throw away all the bogus length che= cks in the upper layers). >> >>If you definitely want to do checking in advance, then that is fine, = too - but don't do it with a test conversion - instead, convert it, che= ck the length of the converted string and then use the converted name f= rom there onwards. >> >>Both my suggestions are perhaps more involved changes than what you a= re doing but I think they are much more worthwhile as they do not intro= duce double the allocations and conversions. >> >>Best regards, >> >>=A0=A0=A0 Anton >> >>On 12 Apr 2014, at 04:26, Hin-Tak Leung wrot= e: >> >> 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