Revert "iputils: Fix build determinism"
PATCH v3 1/2 Revert "iputils: Fix build determinism"
This reverts commit d10da5f6e6d6d3600645dbe43ed412ff23b55095.
--- meta/recipes-extended/iputils/iputils_s20200821.bb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
meta/recipes-extended/iputils/iputils_s20200821.bb +1 -2
@@ -38,8 +38,7 @@ PACKAGECONFIG[docs] = "-DBUILD_HTML_MANS=true -DBUILD_MANS=true,-DBUILD_HTML_MAN inherit meson systemd update-alternatives -# Have to disable setcap/suid as its not deterministic -EXTRA_OEMESON += "--prefix=${root_prefix}/ -DNO_SETCAP_OR_SUID=true" +EXTRA_OEMESON += "--prefix=${root_prefix}/" ALTERNATIVE_PRIORITY = "100"
Signature · 1 line
2.25.1
PATCH v3 2/2 iputils: Fix setcap/setuid of executables
Limit setcap search to PATH for cross builds preventing host contamination. Add DEPENDS for libcap-native to supply this for PACKAGECONFIG libcap.
The previous setting of NO_SETCAP_OR_SUID broke setuid or setcap of /bin/ping and other executables.
--- ...tcap-search-to-PATH-for-cross-builds.patch | 33 +++++++++++++++++++ .../iputils/iputils_s20200821.bb | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +33 -0
@@ -0,0 +1,33 @@ +From aedb7811d1e9b0eae5d33b5bed39f6219a06a8dc Mon Sep 17 00:00:00 2001 +From: Jate Sujjavanich <[email protected]> +Date: Thu, 18 Feb 2021 21:35:03 -0500 +Subject: [PATCH] Limit setcap search to PATH for cross builds + +Upstream-Status: Pending +--- + meson.build | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index aff75a2..16bbfb6 100644 +--- a/meson.build ++++ b/meson.build +@@ -215,7 +215,14 @@ config_h = configure_file( + output : 'config.h', + configuration : conf) + +-setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false) ++if meson.is_cross_build() ++ message('limit setcap search to PATH') ++ path_setcap = ['setcap'] ++else ++ message('search for setcap in PATH and admin dirs') ++ path_setcap = ['setcap', '/usr/sbin/setcap', '/sbin/setcap'] ++endif ++setcap = find_program(path_setcap, required : false) + if cap_dep.found() and setcap.found() + perm_type = 'caps' + setcap_path = setcap.path() +-- +2.30.0 +
meta/recipes-extended/iputils/iputils_s20200821.bb +2 -1
@@ -12,6 +12,7 @@ DEPENDS = "gnutls" SRC_URI = "git://github.com/iputils/iputils \ file://0001-rarpd-rdisc-Drop-PrivateUsers.patch \ + file://0001-Limit-setcap-search-to-PATH-for-cross-builds.patch \ " SRCREV = "23c3782ae0c7f9c6ae59dbed8ad9204f8758542b"
@@ -26,7 +27,7 @@ CVE_CHECK_WHITELIST += "CVE-2000-1213 CVE-2000-1214" PACKAGECONFIG ??= "libcap rarpd \ ${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 'ninfod traceroute6', '', d)} \ ${@bb.utils.filter('DISTRO_FEATURES', 'systemd', d)}" -PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcap" +PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcap libcap-native" PACKAGECONFIG[libidn] = "-DUSE_IDN=true, -DUSE_IDN=false, libidn2" PACKAGECONFIG[gettext] = "-DUSE_GETTEXT=true, -DUSE_GETTEXT=false, gettext" PACKAGECONFIG[ninfod] = "-DBUILD_NINFOD=true,-DBUILD_NINFOD=false,"
Signature · 1 line
2.25.1
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
Quoted 42 lines · Jate Sujjavanich
Limit setcap search to PATH for cross builds preventing host contamination. Add DEPENDS for libcap-native to supply this for PACKAGECONFIG libcap.
The previous setting of
NO_SETCAP_OR_SUIDbroke setuid or setcap of/bin/pingand other executables.Signed-off-by Jate Sujjavanich <[email protected]>---
...tcap-search-to-PATH-for-cross-builds.patch | 33 +++++++++++++++++++
.../iputils/iputils_s20200821.bb | 3 +-2 files changed, 35 insertions(+), 1 deletion(-)create mode 100644
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchmeta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +21
-0@@ -0,0 +1,33 @@ +From aedb7811d1e9b0eae5d33b5bed39f6219a06a8dc Mon Sep 17 00:00:00 2001 +From: Jate Sujjavanich <[email protected]> +Date: Thu, 18 Feb 2021 21:35:03 -0500 +Subject: [PATCH] Limit setcap search to PATH for cross builds + +Upstream-Status: Pending +--- + meson.build | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index aff75a2..16bbfb6 100644 +--- a/meson.build ++++ b/meson.build +@@ -215,7 +215,14 @@ config_h = configure_file( + output : 'config.h', + configuration : conf) + +-setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false) ++if meson.is_cross_build() ++ message('limit setcap search to PATH')
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch line 31
Quoted 10 lines
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +10
-0++ path_setcap = ['setcap'] ++else ++ message('search for setcap in PATH and admin dirs') ++ path_setcap = ['setcap', '/usr/sbin/setcap', '/sbin/setcap'] ++endif ++setcap = find_program(path_setcap, required : false) + if cap_dep.found() and setcap.found() + perm_type = 'caps' + setcap_path = setcap.path() +--
This does look like ultimately the better solution, could you send it to iputils and see what they make of it? I'm keen to try and reduce the number of patches we carry and this one looks like a good candiate for them covering the key edge cases as far as I can tell!
Cheers,
Richard
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
I have submitted to the upstream which I believe is the github iputils/iputils project.
My previous thread had the wrong mailing list address, so I am replying to this question here:
Quoted 3 lines
Thinking further, how about changing the PACKAGECONFIG to:
PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false
-DNO_SETCAP_OR_SUID=true, libcap libcap-native"
Quoted 6 lines
?
Cheers,
Richard
This would disable the fallback to setuid if PACKAGECONFIG libcap was disabled.
- Jate
Quoted 71 lines · Richard Purdie
Quoted 7 lines · Jate Sujjavanich
Limit setcap search to PATH for cross builds preventing host contamination. Add DEPENDS for libcap-native to supply this for PACKAGECONFIG libcap.
The previous setting of
NO_SETCAP_OR_SUIDbroke setuid or setcap of/bin/pingand other executables.Quoted 6 lines
Signed-off-by Jate Sujjavanich <[email protected]>--- ...tcap-search-to-PATH-for-cross-builds.patch | 33 +++++++++++++++++++ .../iputils/iputils_s20200821.bb | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchQuoted 2 lines
diff --git
a/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchb/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchQuoted 4 lines
new file mode 100644
index 0000000000..b09cdb5f13
---/dev/null
+++
b/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchQuoted 10 lines
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +9
-0@@ -0,0 +1,33 @@ +From aedb7811d1e9b0eae5d33b5bed39f6219a06a8dc Mon Sep 17 00:00:00 2001 +From: Jate Sujjavanich <[email protected]> +Date: Thu, 18 Feb 2021 21:35:03 -0500 +Subject: [PATCH] Limit setcap search to PATH for cross builds + +Upstream-Status: Pending +--- + meson.build | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-)meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch line 19
Quoted 10 lines
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +10
-0+ +diff --git a/meson.build b/meson.build +index aff75a2..16bbfb6 100644 +--- a/meson.build ++++ b/meson.build +@@ -215,7 +215,14 @@ config_h = configure_file( + output : 'config.h', + configuration : conf) + +-setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap',required : false)
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch line 31
Quoted 13 lines
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +12
-0++if meson.is_cross_build() ++ message('limit setcap search to PATH') ++ path_setcap = ['setcap'] ++else ++ message('search for setcap in PATH and admin dirs') ++ path_setcap = ['setcap', '/usr/sbin/setcap', '/sbin/setcap'] ++endif ++setcap = find_program(path_setcap, required : false) + if cap_dep.found() and setcap.found() + perm_type = 'caps' + setcap_path = setcap.path() +--This does look like ultimately the better solution, could you send it to iputils and see what they make of it? I'm keen to try and reduce the number of patches we carry and this one looks like a good candiate for them covering
the key edge cases as far as I can tell!Cheers,
Richard
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
Quoted 7 lines · Jate Sujjavanich
I have submitted to the upstream which I believe is the github iputils/iputils project.
My previous thread had the wrong mailing list address, so I am replying to this question here:
Quoted 4 lines
Thinking further, how about changing the PACKAGECONFIG to:
PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false -DNO_SETCAP_OR_SUID=true, libcap libcap-native"
Quoted 7 lines
Quoted 5 lines
?
Cheers,
Richard
This would disable the fallback to setuid if PACKAGECONFIG libcap was disabled.
I have fuzzy recollection that the setuid didn't always work on some hosts so had determinism issues of its own which was why it ended up disabled. It also presented a little less of a security issue that way, although would make certain operations harder.
Cheers,
Richard
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
In reply to Jate SujjavanichHi Jate,
IMHO as I mention on the last version of this patch
the file 0001-Limit-setcap-search-to-PATH-for-cross-builds.patch is not needed
to make the iputils deterministic, the PACKAGECONFIG[libcap] changes on this [Patch 2/2] will do it.
On [Patch 1/2] the option -DNO_SETCAP_OR_SUID=true has been removed with the reverted change.
This will make the meson to use the setuid when setcap and libcap not found and -DUSE_CAP=false.
Only with the addition of the libcap-native on the DEPENDS the meson will use the native setcap
without host contamination.
When the libcap package config is enabled (default option). The libcap-native will provide the setcap binary in the sysoot native STAGING_DIR_NATIVE so the meson
will find the setcaps binary on the STAGING_DIR_NATIVE.
The find_program('setcaps', ....) will return the full path of the native setcap and not the host setcap.
Without the libcap-native the meson find_program('setcaps', ....) will fail to find the first argument
because it not found on the PATH and will fallback to the next argument. The next argument have a full PATH so the find_program will find on the host in this case
and this will cause the contamination.
from the meson help:
program find_program(program_name1, program_name2, ...)
program_name1 here is a string that can be an executable or script to be searched for in PATH or other places inside the project.
(since 0.37.0) program_name2 and later positional arguments are used as fallback strings to search for.
This is meant to be used for cases where the program may have many alternative names, such as foo and foo.py.
The function will check for the arguments one by one and the first one that is found is returned.
Jose
Jate Sujjavanich <[email protected]> escreveu no dia sexta, 19/02/2021 à(s) 17:53:
Quoted 88 lines
Limit setcap search to PATH for cross builds preventing host contamination. Add DEPENDS for libcap-native to supply this for PACKAGECONFIG libcap.
The previous setting of
NO_SETCAP_OR_SUIDbroke setuid or setcap of/bin/pingand other executables.Signed-off-by Jate Sujjavanich <[email protected]>--- ...tcap-search-to-PATH-for-cross-builds.patch | 33 +++++++++++++++++++ .../iputils/iputils_s20200821.bb | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchdiff --git
a/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchb/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchnew file mode 100644
index 0000000000..b09cdb5f13
---/dev/null
+++b/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchmeta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +19
-0@@ -0,0 +1,33 @@ +From aedb7811d1e9b0eae5d33b5bed39f6219a06a8dc Mon Sep 17 00:00:00 2001 +From: Jate Sujjavanich <[email protected]> +Date: Thu, 18 Feb 2021 21:35:03 -0500 +Subject: [PATCH] Limit setcap search to PATH for cross builds + +Upstream-Status: Pending +--- + meson.build | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index aff75a2..16bbfb6 100644 +--- a/meson.build ++++ b/meson.build +@@ -215,7 +215,14 @@ config_h = configure_file( + output : 'config.h', + configuration : conf) + +-setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap',required : false)
++ifmeson.is_cross_build()
++ message('limit setcap search to PATH')
++path_setcap= ['setcap']
++else
++ message('search for setcap in PATH and admin dirs')
++path_setcap= ['setcap', '/usr/sbin/setcap', '/sbin/setcap']
++endif
++setcap =find_program(path_setcap, required : false)
+ ifcap_dep.found()andsetcap.found()meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +5
-0+ perm_type = 'caps' + setcap_path = setcap.path() +-- +2.30.0 +meta/recipes-extended/iputils/iputils_s20200821.bb +2
-1@@ -12,6 +12,7 @@ DEPENDS = "gnutls" SRC_URI = "git://github.com/iputils/iputils \ file://0001-rarpd-rdisc-Drop-PrivateUsers.patch \ + file://0001-Limit-setcap-search-to-PATH-for-cross-builds.patch \ " SRCREV = "23c3782ae0c7f9c6ae59dbed8ad9204f8758542b"@@ -26,7 +27,7 @@ CVE_CHECK_WHITELIST += "CVE-2000-1213 CVE-2000-1214" PACKAGECONFIG ??= "libcap rarpd \ ${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 'ninfod traceroute6', '', d)} \ ${@bb.utils.filter('DISTRO_FEATURES', 'systemd', d)}" -PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcap" +PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcaplibcap-native"
PACKAGECONFIG[libidn] = "-DUSE_IDN=true, -DUSE_IDN=false, libidn2" PACKAGECONFIG[gettext] = "-DUSE_GETTEXT=true, -DUSE_GETTEXT=false,
gettext"
PACKAGECONFIG[ninfod] = "-DBUILD_NINFOD=true,-DBUILD_NINFOD=false,"
--
2.25.1
Signature · 3 lines
Best regards, José Quaresma
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
If libcap is disabled in PACKAGECONFIG, then arguments two and three mean find_program find could setcap on the build machine. This would mean it is not strictly determined by the recipe and it's determined by the configuration of the build machine instead.
find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
- Jate
Quoted 143 lines · Jose Quaresma
Hi Jate,
IMHO as I mention on the last version of this patch
the file 0001-Limit-setcap-search-to-PATH-for-cross-builds.patch is not needed
to make the iputils deterministic, the PACKAGECONFIG[libcap] changes on this [Patch 2/2] will do it.On [Patch 1/2] the option -DNO_SETCAP_OR_SUID=true has been removed with the reverted change.
This will make the meson to use the setuid when setcap and libcap not found and -DUSE_CAP=false.Only with the addition of the libcap-native on the DEPENDS the meson will use the native setcap
without host contamination.When the libcap package config is enabled (default option). The libcap-native will provide the setcap binary in the sysoot native
STAGING_DIR_NATIVEso the meson
will find the setcaps binary on theSTAGING_DIR_NATIVE.The
find_program('setcaps', ....)will return the full path of the native setcap and not the host setcap.
Without the libcap-native the mesonfind_program('setcaps', ....)will fail to find the first argument
because it not found on the PATH and will fallback to the next argument. The next argument have a full PATH so thefind_programwill find on the host in this case
and this will cause the contamination.from the meson help:
program
find_program(program_name1, program_name2, ...)
program_name1here is a string that can be an executable or script to be searched for in PATH or other places inside the project. (since 0.37.0)program_name2and later positional arguments are used as fallback strings to search for.
This is meant to be used for cases where the program may have many alternative names, such as foo andfoo.py.
The function will check for the arguments one by one and the first one that is found is returned.Jose
Jate Sujjavanich <[email protected]> escreveu no dia sexta, 19/02/2021 à(s) 17:53:
Quoted 79 lines
Limit setcap search to PATH for cross builds preventing host contamination. Add DEPENDS for libcap-native to supply this for PACKAGECONFIG libcap.
The previous setting of
NO_SETCAP_OR_SUIDbroke setuid or setcap of/bin/pingand other executables.Signed-off-by Jate Sujjavanich <[email protected]>--- ...tcap-search-to-PATH-for-cross-builds.patch | 33 +++++++++++++++++++ .../iputils/iputils_s20200821.bb | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchdiff --git
a/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchb/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchnew file mode 100644
index 0000000000..b09cdb5f13
---/dev/null
+++b/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchmeta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +19
-0@@ -0,0 +1,33 @@ +From aedb7811d1e9b0eae5d33b5bed39f6219a06a8dc Mon Sep 17 00:00:00 2001 +From: Jate Sujjavanich <[email protected]> +Date: Thu, 18 Feb 2021 21:35:03 -0500 +Subject: [PATCH] Limit setcap search to PATH for cross builds + +Upstream-Status: Pending +--- + meson.build | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index aff75a2..16bbfb6 100644 +--- a/meson.build ++++ b/meson.build +@@ -215,7 +215,14 @@ config_h = configure_file( + output : 'config.h', + configuration : conf) + +-setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap',required : false)
++ifmeson.is_cross_build()
++ message('limit setcap search to PATH')
++path_setcap= ['setcap']
++else
++ message('search for setcap in PATH and admin dirs')
++path_setcap= ['setcap', '/usr/sbin/setcap', '/sbin/setcap']
++endif
++setcap =find_program(path_setcap, required : false)
+ ifcap_dep.found()andsetcap.found()meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +5
-0+ perm_type = 'caps' + setcap_path = setcap.path() +-- +2.30.0 +meta/recipes-extended/iputils/iputils_s20200821.bb +2
-1@@ -12,6 +12,7 @@ DEPENDS = "gnutls" SRC_URI = "git://github.com/iputils/iputils \ file://0001-rarpd-rdisc-Drop-PrivateUsers.patch \ + file://0001-Limit-setcap-search-to-PATH-for-cross-builds.patch \ " SRCREV = "23c3782ae0c7f9c6ae59dbed8ad9204f8758542b"@@ -26,7 +27,7 @@ CVE_CHECK_WHITELIST += "CVE-2000-1213 CVE-2000-1214" PACKAGECONFIG ??= "libcap rarpd \ ${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 'ninfod traceroute6', '', d)} \ ${@bb.utils.filter('DISTRO_FEATURES', 'systemd', d)}" -PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcap" +PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcapQuoted 9 lines
libcap-native"
PACKAGECONFIG[libidn] = "-DUSE_IDN=true, -DUSE_IDN=false, libidn2" PACKAGECONFIG[gettext] = "-DUSE_GETTEXT=true, -DUSE_GETTEXT=false,
gettext"
PACKAGECONFIG[ninfod] = "-DBUILD_NINFOD=true,-DBUILD_NINFOD=false,"
--
2.25.1--
Best regards,José Quaresma
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
Hi,
Jate Sujjavanich <[email protected]> escreveu no dia segunda, 22/02/2021 à(s) 15:58:
Quoted 5 lines
If libcap is disabled in PACKAGECONFIG, then arguments two and three mean
find_programfind could setcap on the build machine. This would mean it is not strictly determined by the recipe and it's determined by the configuration of the build machine instead.
In this case the meson will not use the setcap from the build machine because the libcap not found on the target sysroot.
The libcap is a dependencie when PACKAGECONFIG+="libcap" and in this case the meson it will fallback to use setuid.
https://github.com/iputils/iputils/blob/f0c64bbb2b1563647bfeeed8d82bc4d2d2312d8a/meson.build#L221
But as Richard says the setuid can be problematic too!
Quoted 152 lines
find_program('setcap', '
/usr/sbin/setcap', '/sbin/setcap', required :
false)- Jate
Quoted 143 lines · Jose Quaresma
Hi Jate,
IMHO as I mention on the last version of this patch
the file 0001-Limit-setcap-search-to-PATH-for-cross-builds.patch is not needed
to make the iputils deterministic, the PACKAGECONFIG[libcap] changes on this [Patch 2/2] will do it.On [Patch 1/2] the option -DNO_SETCAP_OR_SUID=true has been removed with the reverted change.
This will make the meson to use the setuid when setcap and libcap not found and -DUSE_CAP=false.Only with the addition of the libcap-native on the DEPENDS the meson will use the native setcap
without host contamination.When the libcap package config is enabled (default option). The libcap-native will provide the setcap binary in the sysoot native
STAGING_DIR_NATIVEso the meson
will find the setcaps binary on theSTAGING_DIR_NATIVE.The
find_program('setcaps', ....)will return the full path of the native setcap and not the host setcap.
Without the libcap-native the mesonfind_program('setcaps', ....)will fail to find the first argument
because it not found on the PATH and will fallback to the next argument. The next argument have a full PATH so thefind_programwill find on the host in this case
and this will cause the contamination.from the meson help:
program
find_program(program_name1, program_name2, ...)
program_name1here is a string that can be an executable or script to be searched for in PATH or other places inside the project. (since 0.37.0)program_name2and later positional arguments are used as fallback strings to search for.
This is meant to be used for cases where the program may have many alternative names, such as foo andfoo.py.
The function will check for the arguments one by one and the first one that is found is returned.Jose
Jate Sujjavanich <[email protected]> escreveu no dia sexta, 19/02/2021 à(s) 17:53:
Quoted 79 lines
Limit setcap search to PATH for cross builds preventing host contamination. Add DEPENDS for libcap-native to supply this for PACKAGECONFIG libcap.
The previous setting of
NO_SETCAP_OR_SUIDbroke setuid or setcap of/bin/pingand other executables.Signed-off-by Jate Sujjavanich <[email protected]>--- ...tcap-search-to-PATH-for-cross-builds.patch | 33 +++++++++++++++++++ .../iputils/iputils_s20200821.bb | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644
meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchdiff --git
a/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchb/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchnew file mode 100644
index 0000000000..b09cdb5f13
---/dev/null
+++b/meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patchmeta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +19
-0@@ -0,0 +1,33 @@ +From aedb7811d1e9b0eae5d33b5bed39f6219a06a8dc Mon Sep 17 00:00:00 2001 +From: Jate Sujjavanich <[email protected]> +Date: Thu, 18 Feb 2021 21:35:03 -0500 +Subject: [PATCH] Limit setcap search to PATH for cross builds + +Upstream-Status: Pending +--- + meson.build | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index aff75a2..16bbfb6 100644 +--- a/meson.build ++++ b/meson.build +@@ -215,7 +215,14 @@ config_h = configure_file( + output : 'config.h', + configuration : conf) + +-setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap',required : false)
++ifmeson.is_cross_build()
++ message('limit setcap search to PATH')
++path_setcap= ['setcap']
++else
++ message('search for setcap in PATH and admin dirs')
++path_setcap= ['setcap', '/usr/sbin/setcap', '/sbin/setcap']
++endif
++setcap =find_program(path_setcap, required : false)
+ ifcap_dep.found()andsetcap.found()meta/recipes-extended/iputils/iputils/0001-Limit-setcap-search-to-PATH-for-cross-builds.patch new file +5
-0+ perm_type = 'caps' + setcap_path = setcap.path() +-- +2.30.0 +meta/recipes-extended/iputils/iputils_s20200821.bb +2
-1@@ -12,6 +12,7 @@ DEPENDS = "gnutls" SRC_URI = "git://github.com/iputils/iputils \ file://0001-rarpd-rdisc-Drop-PrivateUsers.patch \ + file://0001-Limit-setcap-search-to-PATH-for-cross-builds.patch \ " SRCREV = "23c3782ae0c7f9c6ae59dbed8ad9204f8758542b"@@ -26,7 +27,7 @@ CVE_CHECK_WHITELIST += "CVE-2000-1213 CVE-2000-1214" PACKAGECONFIG ??= "libcap rarpd \ ${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 'ninfod traceroute6', '', d)} \ ${@bb.utils.filter('DISTRO_FEATURES', 'systemd', d)}" -PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcap" +PACKAGECONFIG[libcap] = "-DUSE_CAP=true, -DUSE_CAP=false, libcapQuoted 9 lines
libcap-native"
PACKAGECONFIG[libidn] = "-DUSE_IDN=true, -DUSE_IDN=false, libidn2" PACKAGECONFIG[gettext] = "-DUSE_GETTEXT=true, -DUSE_GETTEXT=false,
gettext"
PACKAGECONFIG[ninfod] = "-DBUILD_NINFOD=true,-DBUILD_NINFOD=false,"
--
2.25.1--
Best regards,José Quaresma
Signature · 3 lines
Best regards, José Quaresma
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
Quoted 9 lines · Jose Quaresma
Hi,
Jate Sujjavanich <[email protected]> escreveu no dia segunda, 22/02/2021 à(s) 15:58:
Quoted 5 lines
If libcap is disabled in PACKAGECONFIG, then arguments two and three mean
find_programfind could setcap on the build machine. This would mean it is
not strictly determined by the recipe and it's determined by the
configuration of the build machine instead.
Quoted 5 lines
In this case the meson will not use the setcap from the build machine because the libcap not found on the target sysroot. The libcap is a dependencie when PACKAGECONFIG+="libcap" and in this case the meson it will fallback to use setuid.
https://github.com/iputils/iputils/blob/f0c64bbb2b1563647bfeeed8d82bc4d2d2312d8a/meson.build#L221
Whilst it may not use libcap, I seem to remember issues with the output still not being deterministic since there was something in the out which indicated the presence of setcap (or not).
Cheers,
Richard
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
I tested removing the cross-compile detection patch and removing libcap from PACKAGECONFIG. The build does find setcap on the build machine.
log.do_configure:
CONFIGURATION
Capatiblity (with libcap): false
...
Program /usr/sbin/setcap found: YES (/usr/sbin/setcap)
However, meson did pass perm_type = setuid to setcap-setuid.sh.
log.do_install
[1/2] /workdir/poky/build/tmp/work/core2-64-poky-linux/iputils/s20200821-r0/reci pe-sysroot-native/usr/bin/meson install --no-rebuildsetcap-setuid.sh: changing '/workdir/poky/build/tmp/work/core2-64-poky-linux/ipu tils/s20200821-r0/image//bin/ping' to be setuid root executable
ownership of '/workdir/poky/build/tmp/work/core2-64-poky-linux/iputils/s20200821-r0/image//bin/ping' retained as root
The conditional code in meson.build does fall back to setuid mode based on the presence of libcap stored in cap_dep.found(). So I think you are right, Jose.
if cap_dep.found() and setcap.found()
perm_type = 'caps'
setcap_path = setcap.path()
else
perm_type = 'setuid'
setcap_path = '/dev/null'
endif
And setcap-setuid.sh uses a simple chown and chmod. I *think* these are universal in posix and that we don't have to worry about host contamination.
setuid)
_log "changing '$exec_path' to be setuid root executable" chown -v root "$exec_path"
chmod -v u+s "$exec_path"
- Jate
Quoted 32 lines · Richard Purdie
Quoted 3 lines · Jose Quaresma
Hi,
Jate Sujjavanich <[email protected]> escreveu no dia segunda,
22/02/2021 à(s) 15:58:
Quoted 1 line
Quoted 1 line
If libcap is disabled in PACKAGECONFIG, then arguments two and three
mean
Quoted 1 line
Quoted 1 line
find_programfind could setcap on the build machine. This would meanit is
Quoted 5 lines
Quoted 3 lines
not strictly determined by the recipe and it's determined by the
configuration of the build machine instead.In this case the meson will not use the setcap from the build machine
because
Quoted 1 line
the libcap not found on the target sysroot. The libcap is a dependencie
when
Quoted 1 line
PACKAGECONFIG+="libcap" and in this case the meson it will fallback to
use
Quoted 2 lines
setuid.
https://github.com/iputils/iputils/blob/f0c64bbb2b1563647bfeeed8d82bc4d2d2312d8a/meson.build#L221
Whilst it may not use libcap, I seem to remember issues with the output still not being deterministic since there was something in the out which indicated the presence of setcap (or not).
Cheers,
Richard
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
Hi Jate,
Is that behavior that you explain that I am trying to said.
Jate Sujjavanich <[email protected]> escreveu no dia quarta, 24/02/2021 à(s) 17:19:
Quoted 78 lines
I tested removing the cross-compile detection patch and removing libcap from PACKAGECONFIG. The build does find setcap on the build machine.
log.do_configure:
CONFIGURATION
Capatiblity (with libcap): false
...
Program/usr/sbin/setcapfound: YES (/usr/sbin/setcap)However, meson did pass
perm_type= setuid tosetcap-setuid.sh.log.do_install
[1/2] /workdir/poky/build/tmp/work/core2-64-poky-linux/iputils/s20200821-r0/reci pe-sysroot-native/usr/bin/meson install --no-rebuildsetcap-setuid.sh: changing '/workdir/poky/build/tmp/work/core2-64-poky-linux/ipu tils/s20200821-r0/image//bin/ping' to be setuid root executable
ownership of '/workdir/poky/build/tmp/work/core2-64-poky-linux/iputils/s20200821-r0/image//bin/ping' retained as rootThe conditional code in meson.build does fall back to setuid mode based on the presence of libcap stored in
cap_dep.found(). So I think you are right, Jose.
ifcap_dep.found()andsetcap.found()
perm_type= 'caps'
setcap_path=setcap.path()
else
perm_type= 'setuid'
setcap_path= '/dev/null'
endifAnd
setcap-setuid.shuses a simple chown and chmod. I *think* these are universal in posix and that we don't have to worry about host contamination.
setuid)
_log"changing '$exec_path' to be setuid root executable" chown -v root "$exec_path"
chmod -v u+s "$exec_path"- Jate
Quoted 32 lines · Richard Purdie
Quoted 3 lines · Jose Quaresma
Hi,
Jate Sujjavanich <[email protected]> escreveu no dia segunda,
22/02/2021 à(s) 15:58:
Quoted 1 line
Quoted 1 line
If libcap is disabled in PACKAGECONFIG, then arguments two and three
mean
Quoted 1 line
Quoted 1 line
find_programfind could setcap on the build machine. This would meanit is
Quoted 5 lines
Quoted 3 lines
not strictly determined by the recipe and it's determined by the
configuration of the build machine instead.In this case the meson will not use the setcap from the build machine
because
Quoted 1 line
the libcap not found on the target sysroot. The libcap is a dependencie
when
Quoted 1 line
PACKAGECONFIG+="libcap" and in this case the meson it will fallback to
use
Quoted 2 lines
setuid.
https://github.com/iputils/iputils/blob/f0c64bbb2b1563647bfeeed8d82bc4d2d2312d8a/meson.build#L221
Whilst it may not use libcap, I seem to remember issues with the output still not being deterministic since there was something in the out which indicated the presence of setcap (or not).
Cheers,
Richard
Signature · 3 lines
Best regards, José Quaresma
Re: [PATCH v3 2/2] iputils: Fix setcap/setuid of executables
Jose,
Yes, I forgot to add a sentence saying that my testing confirmed what you said. Your explanation was helpful in learning about this meson build.
- Jate
Quoted 91 lines · Jose Quaresma
Hi Jate,
Is that behavior that you explain that I am trying to said.
Jate Sujjavanich <[email protected]> escreveu no dia quarta, 24/02/2021 à(s) 17:19:
Quoted 40 lines
I tested removing the cross-compile detection patch and removing libcap from PACKAGECONFIG. The build does find setcap on the build machine.
log.do_configure:
CONFIGURATION
Capatiblity (with libcap): false
...
Program/usr/sbin/setcapfound: YES (/usr/sbin/setcap)However, meson did pass
perm_type= setuid tosetcap-setuid.sh.log.do_install
[1/2] /workdir/poky/build/tmp/work/core2-64-poky-linux/iputils/s20200821-r0/reci pe-sysroot-native/usr/bin/meson install --no-rebuildsetcap-setuid.sh: changing '/workdir/poky/build/tmp/work/core2-64-poky-linux/ipu tils/s20200821-r0/image//bin/ping' to be setuid root executable
ownership of '/workdir/poky/build/tmp/work/core2-64-poky-linux/iputils/s20200821-r0/image//bin/ping' retained as rootThe conditional code in meson.build does fall back to setuid mode based on the presence of libcap stored in
cap_dep.found(). So I think you are right, Jose.
ifcap_dep.found()andsetcap.found()
perm_type= 'caps'
setcap_path=setcap.path()
else
perm_type= 'setuid'
setcap_path= '/dev/null'
endifAnd
setcap-setuid.shuses a simple chown and chmod. I *think* these are universal in posix and that we don't have to worry about host contamination.
setuid)
_log"changing '$exec_path' to be setuid root executable" chown -v root "$exec_path"
chmod -v u+s "$exec_path"Quoted 38 lines
- Jate
Quoted 32 lines · Richard Purdie
Quoted 3 lines · Jose Quaresma
Hi,
Jate Sujjavanich <[email protected]> escreveu no dia segunda,
22/02/2021 à(s) 15:58:
Quoted 1 line
Quoted 1 line
If libcap is disabled in PACKAGECONFIG, then arguments two and three
mean
Quoted 1 line
Quoted 1 line
find_programfind could setcap on the build machine. This would meanit is
Quoted 5 lines
Quoted 3 lines
not strictly determined by the recipe and it's determined by the
configuration of the build machine instead.In this case the meson will not use the setcap from the build machine
because
Quoted 1 line
the libcap not found on the target sysroot. The libcap is a
dependencie when
Quoted 1 line
PACKAGECONFIG+="libcap" and in this case the meson it will fallback to
use
Quoted 2 lines
setuid.
https://github.com/iputils/iputils/blob/f0c64bbb2b1563647bfeeed8d82bc4d2d2312d8a/meson.build#L221
Whilst it may not use libcap, I seem to remember issues with the output still not being deterministic since there was something in the out which indicated the presence of setcap (or not).
Cheers,
Richard
--
Best regards,José Quaresma