<div>Hi.</div><div> </div><div>I checked <a href="https://github.com/jobol/toybox/tree/smack-10" target="_blank">https://github.com/jobol/toybox/tree/smack-10</a> and It is good to make common lib/security.h</div><div> </div><div>And, found that seclabel() still calls __security_fget_context()__ only, without handling fd failed cases.</div><div> </div><div>According to your opinion as below : </div><div><em><font color="#999999"> if getting file descriptor is either not possible (symbolic links,<br> socket) or returns an error, then get the path, else use the file<br> descriptor.</font></em></div><div> </div><div>Could you modify here if necessary? I want to know any direction.</div><div>Further, Can I know your test environment?</div><div> </div><div>Thank you.</div><div> </div><div><br> </div><div class="gmail_quote">2015-05-18 16:48 GMT+09:00 José Bollo <span dir="ltr"><<a href="mailto:jobol@nonadev.net" target="_blank">jobol@nonadev.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div class="HOEnZb"><div class="h5">Le lundi 18 mai 2015 à 12:26 +0900, Hyejin Kim a écrit :<br>
> Hi.<br>
><br>
> Recently smack feature is added by ls command only and I tested it on<br>
> emulator of tizen platform.<br>
> But, some operations are not proper at my point of view and I'll share<br>
> them.<br>
><br>
> Below is the smack code at seclabel().<br>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
> } else if (CFG_TOYBOX_SMACK) {<br>
> int fd = openat(dirtree_parentfd(dt), dt->name, O_PATH|<br>
> O_NOFOLLOW);<br>
> char buf[SMACK_LABEL_LEN+1];<br>
> ssize_t len = 1;<br>
> strcpy(buf, "?");<br>
> if (fd != -1) {<br>
> len = fgetxattr(fd, XATTR_NAME_SMACK, pad?buf:0,<br>
> pad?SMACK_LABEL_LEN:0);<br>
> close(fd);<br>
> if (len<1 || len>SMACK_LABEL_LEN) len = 0;<br>
> else buf[len] = 0;<br>
> }<br>
> if (pad) printf(" %*s "+(pad>0), pad, buf);<br>
> return len;<br>
> }<br>
><br>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
><br>
> 1. At first, fd is wrong. So, cant call fgetxattr() and print ? for<br>
> label.<br>
<br>
</div></div>Hi Hyejin, hi all,<br>
<br>
yes it is normal, opening with O_PATH doesn't allow to call fgetxattr.<br>
<span><br>
<br>
> 2. 3rd and 4th param of fgetxattr() is changable for __pad__. but why<br>
> should the __pad__ affect them?<br>
<br>
</span>Having pad=0 means that only the size of the label is checked but the<br>
label has not to be printed. Thus the only meaningful data is the<br>
length. Passing a buffer would imply some unneeded copies of memory.<br>
<span><br>
> 3. If it is hard to get fd, can change to call getxattr() with<br>
> filepath instead of calling fgetxattr with fd. I got a right result on<br>
> emulator with belowing example.<br>
<br>
</span>True. But having a file descriptor instead of a path is optimal.<br>
<br>
In my last proposal <a href="https://github.com/jobol/toybox/tree/smack-10" target="_blank">https://github.com/jobol/toybox/tree/smack-10</a> this<br>
algorithm is used:<br>
<br>
if getting file descriptor is either not possible (symbolic links,<br>
socket) or returns an error, then get the path, else use the file<br>
descriptor.<br>
<br>
For most objects of the file system: regular files and directories, the<br>
file descriptor is used.<br>
<br>
Best regards<br>
José Bollo<br>
<span><br>
> For example :<br>
><br>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
> } else if (CFG_TOYBOX_SMACK) {<br>
> char* path = dirtree_path(dt, 0);<br>
> char buf[SMACK_LABEL_LEN+1];<br>
> ssize_t len = 1;<br>
> strcpy(buf, "?");<br>
> if (path) {<br>
> len = getxattr(path, XATTR_NAME_SMACK, buf, SMACK_LABEL_LEN);<br>
> if (len<1 || len>SMACK_LABEL_LEN) len = 0;<br>
> else buf[len] = 0;<br>
> }<br>
> printf(" %*s "+(pad>0), pad, buf);<br>
> return len;<br>
> }<br>
><br>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
><br>
> Can anyone give me an opinion?<br>
><br>
> Thanks.<br>
><br>
><br>
</span>> _______________________________________________<br>
> Toybox mailing list<br>
> <a href="mailto:Toybox@lists.landley.net">Toybox@lists.landley.net</a><br>
> <a href="http://lists.landley.net/listinfo.cgi/toybox-landley.net" target="_blank">http://lists.landley.net/listinfo.cgi/toybox-landley.net</a><br>
<br>
<br>
</blockquote></div><br>