Bug 234713

Summary: under linux emulation listxattr returns incorrect result
Product: Base System Reporter: weiss
Component: kernAssignee: freebsd-emulation (Nobody) <emulation>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, fsu, markj
Priority: --- Keywords: patch
Version: 11.2-RELEASE   
Hardware: Any   
OS: Any   

Description weiss 2019-01-07 21:35:21 UTC
after upgrade from 11.1 to 11.2 release tivoli storage manager client (TSM)
fails due to incorrect listxattr implementation.

listxattr should return error -EOPNOTSUPP if file system does not support
   extended attributes and no error and result 0 if file does not have
   extended attributes. With 11.2 listxattr returns -ENODATA in the
   second case.

On linux output of strace of listxattr of directory ./nano without
  extended attributes:
  
  listxattr(".nano/", NULL, 0)            = 0

On FreeBSD output of ktrace of listxattr of directory without
  extended attributes:

 54332 dsmc     RET   linux_llistxattr -1 errno -61 Attribute not found


Following change in code between 11.1 and 11.2 led to the emergence of the bug.
In 11.1 EOPNOTSUPP was returned instead of ENODATA. This change may seem correct for other linux xattr calls, but not for listxattr.


*** linux32_sysvec.c    Mon Jan  7 18:30:21 2019
--- linux32_sysvec.c-11.2       Fri Jun 22 01:02:23 2018
***************
*** 146,152 ****
        -100,-101,-102,-103,-104,-105,-106,-107,-108,-109,
        -110,-111, -40, -36,-112,-113, -39, -11, -87,-122,
        -116, -66,  -6,  -6,  -6,  -6,  -6, -37, -38,  -9,
!         -6,  -6, -43, -42, -75,-125, -84, -95, -16, -74,
         -72, -67, -71
  };
  
--- 146,152 ----
        -100,-101,-102,-103,-104,-105,-106,-107,-108,-109,
        -110,-111, -40, -36,-112,-113, -39, -11, -87,-122,
        -116, -66,  -6,  -6,  -6,  -6,  -6, -37, -38,  -9,
!         -6,  -6, -43, -42, -75,-125, -84, -61, -16, -74,
         -72, -67, -71
  };
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2019-01-08 02:20:38 UTC
Seems to be a regression from r326282.  Shouldn't the change have also modified the xattr stubs to return EOPNOTSUPP instead of ENOATTR?
Comment 2 Fedor Uporov freebsd_committer freebsd_triage 2019-01-09 09:55:58 UTC
The listxattr and other extattr related linux emulator calls are implemented as dummy calls.
See DUMMY_XATTR macro in the linux_dummy.c. The dummy calls return values are ENOATTR in all cases. After the bsd_to_linux_errno mapping the linux ENODATA (-61) will be returned.
Before the r326282 it was linux EOPNOTSUPP (-95).
It is possible to change dummy calls return values from ENOATTR to EOPNOTSUPP.
I am not clearly understand, why it was not done from beginning? Is it possible to affect someone if the error code will be changed?
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2019-01-09 16:41:16 UTC
(In reply to Fedor Uporov from comment #2)
Indeed, I think the stubs should be modified to return EOPNOTSUPP.  I'm not sure why it wasn't that way before... with the previous translation of ENOATTR it just "worked" so I guess it was a bug that nobody noticed.  Since you were in that area, would you like to fix it?
Comment 4 Fedor Uporov freebsd_committer freebsd_triage 2019-01-09 16:55:10 UTC
(In reply to Mark Johnston from comment #3)
Ok, I will prepare the phabricator review soon.
Comment 5 Fedor Uporov freebsd_committer freebsd_triage 2019-01-13 12:15:11 UTC
MFC`ed to stable/11.
Revision: r342999