Bug 13269 - Build fails if host 'file' has seccomp enabled
Summary: Build fails if host 'file' has seccomp enabled
Status: RESOLVED WONTFIX
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: oe-core other (show other bugs)
Version: 0.0.0
Hardware: x86 Multiple
: Medium normal
Target Milestone: 3.1
Assignee: Ross Burton
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2019-04-08 15:54 UTC by Juro Bystricky
Modified: 2019-10-19 11:10 UTC (History)
2 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: New (Never tested)
Verified:
Documentation change: Don't know


Attachments
patch fixing the reported problem (524 bytes, patch)
2019-04-08 15:55 UTC, Juro Bystricky
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Juro Bystricky 2019-04-08 15:54:32 UTC
If the yocto host system has seccomp provisions, any packaging command will fail with the following (example):

Command '['file', '-b', '/home/juro/yocto/poky/build-thud/tmp/work/armv5e-poky-linux-gnueabi/file/5.34-r0/package/usr/lib/libmagic.so.1.0.0']' died with <Signals.SIGSYS: 31>.: Traceback (most recent call last):                                       
  File "/home/juro/yocto/poky/meta/lib/oe/utils.py", line 272, in run                                                                                                                                                                                    
    ret = self._target(*self._args, **self._kwargs)                                                                                                                                                                                                      
  File "/home/juro/yocto/poky/meta/lib/oe/package.py", line 70, in is_elf                                                                                                                                                                                
    result = subprocess.check_output(["file", "-b", path], stderr=subprocess.STDOUT).decode("utf-8")                                                                                                                                                     
  File "/usr/lib/python3.7/subprocess.py", line 395, in check_output                                                                                                                                                                                     
    **kwargs).stdout                                                                                                                                                                                                                                     
  File "/usr/lib/python3.7/subprocess.py", line 487, in run                                                                                                                                                                                              
    output=stdout, stderr=stderr)                                                                                                                                                                                                                        
subprocess.CalledProcessError: Command '['file', '-b', '/home/juro/yocto/poky/build-thud/tmp/work/armv5e-poky-linux-gnueabi/file/5.34-r0/package/usr/lib/libmagic.so.1.0.0']' died with <Signals.SIGSYS: 31>.                                            


ERROR: file-5.34-r0 do_package: Function failed: split_and_strip_files

This patch fixes the problem:

===================

diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index efd36b3758..38afeb4244 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -67,7 +67,7 @@ def is_kernel_module_signed(path):
 # 16 - kernel module
 def is_elf(path):
     exec_type = 0
-    result = subprocess.check_output(["file", "-b", path], stderr=subprocess.STDOUT).decode("utf-8")
+    result = subprocess.check_output(["file", "-bS", path], stderr=subprocess.STDOUT).decode("utf-8")
 
     if "ELF" in result:
         exec_type |= 1
=====================

(see man file "S" option)
Comment 1 Juro Bystricky 2019-04-08 15:55:13 UTC
Created attachment 4464 [details]
patch fixing the reported problem
Comment 2 Ross Burton 2019-04-08 16:16:07 UTC
Interestingly my build of file-native from master doesn't have a -S option.
Comment 3 Juro Bystricky 2019-04-08 16:42:05 UTC
On my host:

$ file --version
file-5.36
magic file from /usr/share/file/magic
Comment 4 Juro Bystricky 2019-04-08 16:44:10 UTC
(In reply to comment #2)
> Interestingly my build of file-native from master doesn't have a -S option.

The "file" being used comes from HOSTTOOLS, I am not sure why we don't use our file-native.
Comment 5 Ross Burton 2019-08-08 15:19:30 UTC
What host distro was this?  I'm guessing Clear Linux.  Can you still replicate this?

There's presumably some conflict between seccomp and pseudo.  I wonder if it's possible to disable seccomp in file without passing an option so we don't need to detect if seccomp is enabled before every invocation of file.
Comment 6 Ross Burton 2019-08-08 15:20:04 UTC
Current thinking is "can we just mandate that seccomp isn't enabled"?
Comment 7 Juro Bystricky 2019-08-08 15:27:54 UTC
(In reply to comment #6)
> Current thinking is "can we just mandate that seccomp isn't enabled"?

The latest "file" allows the switch -S without seccomp being available.
(Up until then -S was treated as an error in that case). But it will take some time for this to percolate to all distros. So the patch I posted will not work with the old "file" package.
Comment 8 Ross Burton 2019-08-08 15:30:58 UTC
Yes, I saw that. It landed in file five days ago and we still support Centos 7 which is based on Fedora 19, so I don't expect to be able to assume 'file -S' works for a good few years yet.
Comment 9 Ross Burton 2019-08-19 11:36:25 UTC
Interestingly LWN has an article about how Debian tried enabling seccomp for file, and had to turn it off because they use fakeroot (thus, LD_PRELOAD) during package building too:

https://lwn.net/SubscriberLink/796108/95ab278a062b5838/
Comment 10 Randy MacLeod 2019-08-22 14:58:23 UTC
We expect that seccomp for file does now work in general and any distro trying to do so will eventually revet that feature.
Comment 11 Randy MacLeod 2019-08-22 16:28:36 UTC
Correction: 
 seccomp for 'file' does *not* work in general
Comment 12 Ross Burton 2019-10-17 15:10:39 UTC
Clear agree that seccomp is stupid and are reverting this.
Comment 13 Ross Burton 2019-10-19 11:10:11 UTC
GNU file and seccomp and LD_PRELOAD (thus, pseudo) just don't get on.

As per comment #9 this isn't specific to us, Debian has come to the same conclusion.

Clear was the only distribution that enabled seccomp in file and as of this commit it doesn't do that any more:

https://github.com/clearlinux-pkgs/file/commit/74624ebb5d803a9ce7cd8c956830983f54451d41

Closing as WONTFIX.  I guess an alternative would be to remove file-native from ASSUME_PROVIDED on these platforms and ensure that file-native is marked as a dependency where it is used, but I don't know if this would actually be possible.