Skip to contentSkip to conversation

core/pkg-infra: allow packages to provide permisions in a file

PATCH New Yann E. MORIN 2 participants 10 messages Dec 13, 2016 – Dec 14, 2016 VFS

lore
Share & tools
lore
#0 lore raw

cover core/pkg-infra: allow packages to provide permisions in a file

Hello All!

This series is a quick proof-of-concpet to allow packages to provide a permission table in a file rather than in-line in the .mk fiile.

That permission file can be generated. It is usefull for the SELinux stuff and busybox, where individual applets should have a suid bit, but we only know what applets exist at configure time, not when parsing the .mk file.

This is RFC material, jsut for quick review of the concept, not the actual code. This is not meant to be applied now.

Regards,
Yann E. MORIN.

The following changes since commit aa9a838364c7d60fd32eb265a88dea17a2be8324

  zlib: use $(HOST_MAKE_ENV) when calling $(MAKE1) (2016-12-13 16:27:34 +0100)

are available in the git repository at:

git://git.buildroot.org/~ymorin/git/buildroot.git

for you to fetch changes up to 6d7c0fcf8647fa6e554e32e0370baec848b9ddef

[RFC] package/busybox: gneerate permissions for enabeld applets (2016-12-13 22:34:36 +0100)

----------------------------------------------------------------
Yann E. MORIN (3):
core: allow packages to declare a permission file docs/manual: document FOO_PERMISSIONS_FILE
[RFC] package/busybox: gneerate permissions for enabeld applets

 docs/manual/adding-packages-generic.txt |  8 +++++++-
 fs/common.mk                            |  1 +
 package/busybox/busybox.mk              | 15 +++++++++++++++
 package/pkg-generic.mk                  |  1 +
 4 files changed, 24 insertions(+), 1 deletion(-)
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH 1/3 core: allow packages to declare a permission file

Currently, packages can define a variable that holds all the permissions to set on the files it installs. This can be used to set various permissions, like ownership, mode, suid/sgid/sticky bits to individual files.

However, this variable has to contain entries that are known the moment we scan the .mk file; it is not possible to conditionally add permisions for files which presence depend on post-parse conditions.

This is the case for example for Busybox, for which we don't know whether a specific applet will be enabled or not until after the configure command has run.

Introduce a new variable that packages can set to point to a file that contains a permission table. That filewill only be used when a filesystem image is asembled, so the file can be generated, either at configure or build time, with no problem.

---
Note: this will be usefull for Busybox, to properly handle the SELinux contexts of the individual applets.

---
 fs/common.mk           | 1 +
 package/pkg-generic.mk | 1 +
 2 files changed, 2 insertions(+)
fs/common.mk +1 -0
index 7515fdc..843f7ca 100644
@@ -90,6 +90,7 @@ ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
 	$$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE)
 endif
 	$$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE)
+	cat $$(PACKAGES_PERMISSIONS_TABLE_FILES) >> $$(FULL_DEVICE_TABLE)
 	echo "$$(HOST_DIR)/usr/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
 endif
 	$$(foreach s,$$(call qstrip,$$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\
package/pkg-generic.mk +1 -0
index 827de62..0f88786 100644
@@ -904,6 +904,7 @@ PACKAGES += $(1)
 ifneq ($$($(2)_PERMISSIONS),)
 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
 endif
+PACKAGES_PERMISSIONS_FILES += $$($(2)_PERMISSIONS_FILE)
 ifneq ($$($(2)_DEVICES),)
 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
 endif
Signature · 1 line
2.7.4
#4 lore raw

PATCH 2/3 docs/manual: document FOO_PERMISSIONS_FILE

In reply to Yann E. MORIN
---
 docs/manual/adding-packages-generic.txt | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
docs/manual/adding-packages-generic.txt +7 -1
index 0e111e1..f23b405 100644
@@ -385,7 +385,13 @@ information is (assuming the package name is +libfoo+) :
 * +LIBFOO_PERMISSIONS+ lists the changes of permissions to be done at
   the end of the build process. The syntax is once again the makedevs one.
   You can find some documentation for this syntax in the xref:makedev-syntax[].
-  This variable is optional.
+  This variable is optional; and its value must be known when the .mk
+  file is parsed.
+
+* +LIBFOO_PERMISSIONS_FILE+, like +LIBFOO_PERMISSIONS+ but points to a
+  file that contains the list of permissions. Unless +LIBFOO_PERMISSIONS+,
+  its content need not be known when the .mk file is parsed, so it can be
+  generated. This variable is optional, and you should seldom need it.
 
 * +LIBFOO_USERS+ lists the users to create for this package, if it installs
   a program you want to run as a specific user (e.g. as a daemon, or as a
Signature · 1 line
2.7.4
#5 lore raw

RFC PATCH 3/3 package/busybox: gneerate permissions for enabeld applets

In reply to Yann E. MORIN

DO NOT COMMIT THIS.

This is jsut an example how to use FOO_PERMISSIONS_FILE.

---
 package/busybox/busybox.mk | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
package/busybox/busybox.mk +15 -0
index f4a241d..9c1f2e8 100644
@@ -60,9 +60,24 @@ BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG
 BUSYBOX_KCONFIG_EDITORS = menuconfig xconfig gconfig
 BUSYBOX_KCONFIG_OPTS = $(BUSYBOX_MAKE_OPTS)
 
+ifeq ($(BR2_PACKAGE_BUSYBOX_INDIVIDUAL_BINARIES),y)
+BUSYBOX_PERMISSIONS_FILE = $(@D)/busybox.permissions
+define BUSYBOX_GEN_PERMISSIONS
+	for app in `grep -r -e "APPLET.*BB_SUID_REQUIRE\|APPLET.*BB_SUID_MAYBE" $(@D)/include/applets.h \
+		| sed -e 's/,.*//' -e 's/.*(//'`; \
+	do \
+		temp=`grep -w $${app} $(@D)/busybox.links`; \
+		if [ -n "$${temp}" ]; then \
+			echo "$${temp} f 4755 0  0 - - - - -"
+		fi; \
+	done >$(BUSYBOX_PERMISSIONS_FILE)
+endef
+BUSYBOX_POST_INSTALL_TARGET_HOOKS += BUSYBOX_GEN_PERMISSIONS
+else
 define BUSYBOX_PERMISSIONS
 	/bin/busybox                     f 4755 0  0 - - - - -
 endef
+endif
 
 # If mdev will be used for device creation enable it and copy S10mdev to /etc/init.d
 ifeq ($(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV),y)
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/3 core: allow packages to declare a permission file

In reply to Yann E. MORIN
Quoted 35 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Currently, packages can define a variable that holds all the permissions to set on the files it installs. This can be used to set various permissions, like ownership, mode, suid/sgid/sticky bits to individual files.

However, this variable has to contain entries that are known the moment we scan the .mk file; it is not possible to conditionally add permisions for files which presence depend on post-parse conditions.

This is the case for example for Busybox, for which we don't know whether a specific applet will be enabled or not until after the configure command has run.

Introduce a new variable that packages can set to point to a file that contains a permission table. That filewill only be used when a filesystem image is asembled, so the file can be generated, either at configure or build time, with no problem.

---
Note: this will be usefull for Busybox, to properly handle the SELinux contexts of the individual applets.

---
 fs/common.mk           | 1 +
 package/pkg-generic.mk | 1 +
 2 files changed, 2 insertions(+)
fs/common.mk +0 -0
index 7515fdc..843f7ca 100644

fs/common.mk ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y) · line 93

Quoted 4 lines
fs/common.mk +1 -0
@@ -90,6 +90,7 @@ ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
 	$$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE)
 endif
 	$$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE)
+	cat $$(PACKAGES_PERMISSIONS_TABLE_FILES) >> $$(FULL_DEVICE_TABLE)

We need to protect against the case where this is empty, similar to how we do it for the rootfs table files.

Notice that you called it PACKAGES_PERMISSIONS_TABLE_FILES here and PACKAGES_PERMISSIONS_FILES elsewhere.

Signature · 1 line
Bye, Peter Korsgaard
#6 lore raw

RFC PATCH 3/3 package/busybox: gneerate permissions for enabeld applets

In reply to Yann E. MORIN
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

DO NOT COMMIT THIS.
This is jsut an example how to use FOO_PERMISSIONS_FILE.

---
 package/busybox/busybox.mk | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
package/busybox/busybox.mk +0 -0
index f4a241d..9c1f2e8 100644

package/busybox/busybox.mk BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG · line 64

Quoted 5 lines
package/busybox/busybox.mk +2 -0
@@ -60,9 +60,24 @@ BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG
 BUSYBOX_KCONFIG_EDITORS = menuconfig xconfig gconfig
 BUSYBOX_KCONFIG_OPTS = $(BUSYBOX_MAKE_OPTS)
 
+ifeq ($(BR2_PACKAGE_BUSYBOX_INDIVIDUAL_BINARIES),y)
+BUSYBOX_PERMISSIONS_FILE = $(@D)/busybox.permissions

Careful, what does $(@D) refer to here? When it is used here in the file it is output/build/busybox-*, but when it is expanded in fs/common.mk it refers to output/images:

cat /home/peko/source/buildroot/output-test/images/busybox.permissions >> /home/peko/source/buildroot/output-test/build/_device_table.txt
cat: /home/peko/source/buildroot/output-test/images/busybox.permissions: No such file or directory

package/busybox/busybox.mk BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG · line 71

Quoted 7 lines
package/busybox/busybox.mk +7 -0
+define BUSYBOX_GEN_PERMISSIONS
+	for app in `grep -r -e "APPLET.*BB_SUID_REQUIRE\|APPLET.*BB_SUID_MAYBE" $(@D)/include/applets.h \
+		| sed -e 's/,.*//' -e 's/.*(//'`; \
+	do \
+		temp=`grep -w $${app} $(@D)/busybox.links`; \
+		if [ -n "$${temp}" ]; then \
+			echo "$${temp} f 4755 0  0 - - - - -"

You forgot to append ; \ so it doesn't actually work.

Signature · 1 line
Bye, Peter Korsgaard
#8 lore raw

cover core/pkg-infra: allow packages to provide permisions in a file

In reply to Yann E. MORIN
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Hello All!
This series is a quick proof-of-concpet to allow packages to provide a permission table in a file rather than in-line in the .mk fiile.

Quoted 7 lines

That permission file can be generated. It is usefull for the SELinux stuff and busybox, where individual applets should have a suid bit, but we only know what applets exist at configure time, not when parsing the .mk file.

This is RFC material, jsut for quick review of the concept, not the actual code. This is not meant to be applied now.

I'm not really happy with having 2 ways of specifying per-package permissions, but OK - perhaps it is the best way of handling this.

Alternatively we could drop the check-for-empty <pkg>_PERMISSIONS in pkg-generic.mk, so PACKAGES_PERMISSIONS only get expanded at filesystem creation time and then do something like:

BUSYBOX_PERMISSIONS = \
        $(if $(shell grep 'CONFIG_PING=y' $(BUSYBOX_BUILD_CONFIG)),/bin/ping f 4755 0  0 - - - - -$(sep)) \
        $(if $(shell grep 'CONFIG_PING6=y' $(BUSYBOX_BUILD_CONFIG)),/bin/ping6 f 4755 0  0 - - - - -$(sep))
        ...

But that also isn't very pretty.

Signature · 1 line
Bye, Peter Korsgaard
#3 lore raw

PATCH 1/3 core: allow packages to declare a permission file

In reply to Peter Korsgaard

Peter, All,

On 2016-12-13 23:28 +0100, Peter Korsgaard spake thusly:

Quoted 30 lines
Quoted 29 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Currently, packages can define a variable that holds all the permissions to set on the files it installs. This can be used to set various permissions, like ownership, mode, suid/sgid/sticky bits to individual files.

However, this variable has to contain entries that are known the moment we scan the .mk file; it is not possible to conditionally add permisions for files which presence depend on post-parse conditions.

This is the case for example for Busybox, for which we don't know whether a specific applet will be enabled or not until after the configure command has run.

Introduce a new variable that packages can set to point to a file that contains a permission table. That filewill only be used when a filesystem image is asembled, so the file can be generated, either at configure or build time, with no problem.

---
Note: this will be usefull for Busybox, to properly handle the SELinux contexts of the individual applets.

---
 fs/common.mk           | 1 +
 package/pkg-generic.mk | 1 +
 2 files changed, 2 insertions(+)
Quoted 12 lines

fs/common.mk ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y) · line 93

Quoted 9 lines
fs/common.mk +1 -0
index 7515fdc..843f7ca 100644
@@ -90,6 +90,7 @@ ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
 	$$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE)
 endif
 	$$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE)
+	cat $$(PACKAGES_PERMISSIONS_TABLE_FILES) >> $$(FULL_DEVICE_TABLE)

We need to protect against the case where this is empty, similar to how we do it for the rootfs table files.

Indeed.

Quoted 2 lines

Notice that you called it PACKAGES_PERMISSIONS_TABLE_FILES here and PACKAGES_PERMISSIONS_FILES elsewhere.

Yup, but as I said in the cover-letter, it was just to show how we could let packages specify a permissions table rather than a in-line value.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#9 lore raw

cover core/pkg-infra: allow packages to provide permisions in a file

In reply to Peter Korsgaard

Peter, All,

On 2016-12-13 23:34 +0100, Peter Korsgaard spake thusly:

Quoted 17 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Hello All!
This series is a quick proof-of-concpet to allow packages to provide a permission table in a file rather than in-line in the .mk fiile.

Quoted 7 lines

That permission file can be generated. It is usefull for the SELinux stuff and busybox, where individual applets should have a suid bit, but we only know what applets exist at configure time, not when parsing the .mk file.

This is RFC material, jsut for quick review of the concept, not the actual code. This is not meant to be applied now.

I'm not really happy with having 2 ways of specifying per-package permissions, but OK - perhaps it is the best way of handling this.

Quoted 7 lines

Alternatively we could drop the check-for-empty <pkg>_PERMISSIONS in pkg-generic.mk, so PACKAGES_PERMISSIONS only get expanded at filesystem creation time and then do something like:

BUSYBOX_PERMISSIONS = \
        $(if $(shell grep 'CONFIG_PING=y' $(BUSYBOX_BUILD_CONFIG)),/bin/ping f 4755 0  0 - - - - -$(sep)) \
        $(if $(shell grep 'CONFIG_PING6=y' $(BUSYBOX_BUILD_CONFIG)),/bin/ping6 f 4755 0  0 - - - - -$(sep))

Which is exactly what I suggested on IRC...

Quoted 1 line

But that also isn't very pretty.

.. and which I also dismissed becayuse it is not nice either.

I prefer that we have a proper infra in place rather than do tricks like that...

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

RFC PATCH 3/3 package/busybox: gneerate permissions for enabeld applets

In reply to Peter Korsgaard

Peter, All,

On 2016-12-13 23:32 +0100, Peter Korsgaard spake thusly:

Quoted 29 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

DO NOT COMMIT THIS.
This is jsut an example how to use FOO_PERMISSIONS_FILE.

---
 package/busybox/busybox.mk | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
package/busybox/busybox.mk +0 -0
index f4a241d..9c1f2e8 100644

package/busybox/busybox.mk BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG · line 64

Quoted 5 lines
package/busybox/busybox.mk +2 -0
@@ -60,9 +60,24 @@ BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG
 BUSYBOX_KCONFIG_EDITORS = menuconfig xconfig gconfig
 BUSYBOX_KCONFIG_OPTS = $(BUSYBOX_MAKE_OPTS)
 
+ifeq ($(BR2_PACKAGE_BUSYBOX_INDIVIDUAL_BINARIES),y)
+BUSYBOX_PERMISSIONS_FILE = $(@D)/busybox.permissions

Careful, what does $(@D) refer to here? When it is used here in the file it is output/build/busybox-*, but when it is expanded in fs/common.mk it refers to output/images:

cat /home/peko/source/buildroot/output-test/images/busybox.permissions >> /home/peko/source/buildroot/output-test/build/_device_table.txt
cat: /home/peko/source/buildroot/output-test/images/busybox.permissions: No such file or directory

Quoted 9 lines

package/busybox/busybox.mk BUSYBOX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG_FRAG · line 71

Quoted 7 lines
package/busybox/busybox.mk +7 -0
+define BUSYBOX_GEN_PERMISSIONS
+	for app in `grep -r -e "APPLET.*BB_SUID_REQUIRE\|APPLET.*BB_SUID_MAYBE" $(@D)/include/applets.h \
+		| sed -e 's/,.*//' -e 's/.*(//'`; \
+	do \
+		temp=`grep -w $${app} $(@D)/busybox.links`; \
+		if [ -n "$${temp}" ]; then \
+			echo "$${temp} f 4755 0  0 - - - - -"

You forgot to append ; \ so it doesn't actually work.

No, it does not. Again, as I said in the cover-letter and in this commit log, it is just a very early smnapshot of the directions we'd have to follow to allow packages to provide non-constant (i.e. generated) permissions, and how relatively easy it would be.

If we ever want to do it, of course.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'