diff mbox series

[v4l-utils,v2,2/2] keytable: cannot load BPF decoders from udevd

Message ID 20191024153305.22150-2-sean@mess.org (mailing list archive)
State New, archived
Headers show
Series [v4l-utils,1/2] sync v4l-utils.spec with the fedora repo | expand

Commit Message

Sean Young Oct. 24, 2019, 3:33 p.m. UTC
By default udevd is not allowed to execute BPF syscalls. Implement
workaround as suggested in:

	https://github.com/systemd/systemd/issues/13787

Signed-off-by: Sean Young <sean@mess.org>
---
 configure.ac                     | 6 ++++++
 utils/keytable/50-rc_keymap.conf | 3 +++
 utils/keytable/Makefile.am       | 3 ++-
 v4l-utils.spec.in                | 2 ++
 4 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 utils/keytable/50-rc_keymap.conf

Comments

Hans Verkuil Oct. 27, 2019, 2:18 p.m. UTC | #1
Hi Sean,

After this was installed on my debian system (running the 'testing' 
version of debian) the laptop would no longer boot since the 
systemd-udevd service failed to load.

My laptop runs systemd 242.

After removing the installed 50-rc_keymap.conf it worked again.

So either this file is no good, or it requires a newer systemd for it to 
work.

Regards,

	Hans

On 10/24/19 5:33 PM, Sean Young wrote:
> By default udevd is not allowed to execute BPF syscalls. Implement
> workaround as suggested in:
> 
> 	https://github.com/systemd/systemd/issues/13787
> 
> Signed-off-by: Sean Young <sean@mess.org>
> ---
>   configure.ac                     | 6 ++++++
>   utils/keytable/50-rc_keymap.conf | 3 +++
>   utils/keytable/Makefile.am       | 3 ++-
>   v4l-utils.spec.in                | 2 ++
>   4 files changed, 13 insertions(+), 1 deletion(-)
>   create mode 100644 utils/keytable/50-rc_keymap.conf
> 
> diff --git a/configure.ac b/configure.ac
> index c84067ae..01a24a28 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -362,6 +362,11 @@ AC_ARG_WITH(udevdir,
>      	[],
>   	[with_udevdir=`$PKG_CONFIG --variable=udevdir udev || echo /lib/udev`])
>   
> +AC_ARG_WITH(systemdsystemunitdir,
> +	AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [set systemd system unit directory]),
> +	[],
> +	[with_systemdsystemunitdir=`$PKG_CONFIG --variable=systemdsystemunitdir systemd || echo /lib/systemd/system`])
> +
>   # Generic check: works with most distributions
>   def_gconv_dir=`for i in /lib64 /usr/lib64 /usr/local/lib64 /lib /usr/lib /usr/local/lib; do if @<:@ -d \$i/gconv @:>@; then echo \$i/gconv; break; fi; done`
>   
> @@ -384,6 +389,7 @@ AC_SUBST([libv4lconvertprivdir], [$libdir/$with_libv4lconvertsubdir])
>   AC_SUBST([keytablesystemdir], [$with_udevdir/rc_keymaps])
>   AC_SUBST([keytableuserdir], [$sysconfdir/rc_keymaps])
>   AC_SUBST([udevrulesdir], [$with_udevdir/rules.d])
> +AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir/systemd-udevd.service.d/])
>   AC_SUBST([pkgconfigdir], [$libdir/pkgconfig])
>   AC_SUBST([gconvsysdir], [$with_gconvdir])
>   
> diff --git a/utils/keytable/50-rc_keymap.conf b/utils/keytable/50-rc_keymap.conf
> new file mode 100644
> index 00000000..6066c50c
> --- /dev/null
> +++ b/utils/keytable/50-rc_keymap.conf
> @@ -0,0 +1,3 @@
> +# ir-keytable needs access to bpf in order load BPF decoders
> +[Service]
> +SystemCallFilter=bpf
> diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
> index d7b30e2c..dfcd7609 100644
> --- a/utils/keytable/Makefile.am
> +++ b/utils/keytable/Makefile.am
> @@ -3,6 +3,7 @@ man_MANS = ir-keytable.1 rc_keymap.5
>   sysconf_DATA = rc_maps.cfg
>   keytablesystem_DATA = $(srcdir)/rc_keymaps/*
>   udevrules_DATA = 70-infrared.rules
> +systemdsystemunit_DATA = 50-rc_keymap.conf
>   
>   ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h keymap.c keymap.h
>   
> @@ -18,7 +19,7 @@ ir_keytable_LDFLAGS += $(LIBELF_LIBS)
>   SUBDIRS = bpf_protocols
>   endif
>   
> -EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace gen_input_events.pl gen_keytables.pl ir-keytable.1 rc_maps.cfg rc_keymap.5
> +EXTRA_DIST = 70-infrared.rules 50-rc_keymap.conf rc_keymaps rc_keymaps_userspace gen_input_events.pl gen_keytables.pl ir-keytable.1 rc_maps.cfg rc_keymap.5
>   
>   check:
>   	@$(foreach keymap,$(wildcard $(keytablesystem_DATA)),./ir-keytable --test-keymap=$(keymap);)
> diff --git a/v4l-utils.spec.in b/v4l-utils.spec.in
> index d9d46706..a368d3fe 100644
> --- a/v4l-utils.spec.in
> +++ b/v4l-utils.spec.in
> @@ -121,6 +121,7 @@ make doxygen-run
>   
>   %install
>   %{!?_udevrulesdir: %global _udevrulesdir /lib/udev/rules.d}
> +%{!?_systemdsystemunitdir: %global _systemdsystemunitdir /lib/systemd/system}
>   %make_install
>   find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
>   rm -f $RPM_BUILD_ROOT%{_libdir}/{v4l1compat.so,v4l2convert.so}
> @@ -142,6 +143,7 @@ desktop-file-validate $RPM_BUILD_ROOT%{_datadir}/applications/qv4l2.desktop
>   %config(noreplace) %{_sysconfdir}/rc_maps.cfg
>   %{_udevrulesdir}/70-infrared.rules
>   %{_udevrulesdir}/../rc_keymaps/*
> +%{_systemdsystemunitdir}/50-rc_keymap.conf
>   %{_bindir}/cx18-ctl
>   %{_bindir}/cec*
>   %{_bindir}/dvb*
>
Sean Young Oct. 27, 2019, 2:54 p.m. UTC | #2
Hi Hans,

On Sun, Oct 27, 2019 at 03:18:55PM +0100, Hans Verkuil wrote:
> Hi Sean,
> 
> After this was installed on my debian system (running the 'testing' version
> of debian) the laptop would no longer boot since the systemd-udevd service
> failed to load.
> 
> My laptop runs systemd 242.
> 
> After removing the installed 50-rc_keymap.conf it worked again.
> 
> So either this file is no good, or it requires a newer systemd for it to
> work.

I think I know what the problem is. On Fedora, for the systemd-udevd.service
there is this setting.
SystemCallFilter=@system-service @module @raw-io
then 50-rc_keymap.conf adds:
SystemCallFilter=bpf
Which is concatenated to the end.

On the debian version of systemd, SystemCallFilter is not set. So
SystemCallFilter=bpf
means that only the bpf syscall is allowed. 

I'm not sure what the correct solution is. I'll try a few things and if I
don't come up with anything, I'll have to revert.

Suggestions welcome :)

Thanks for debugging and reporting.


Sean
Sean Young Oct. 28, 2019, 9:46 a.m. UTC | #3
On Sun, Oct 27, 2019 at 02:54:51PM +0000, Sean Young wrote:
> On Sun, Oct 27, 2019 at 03:18:55PM +0100, Hans Verkuil wrote:
> > After this was installed on my debian system (running the 'testing' version
> > of debian) the laptop would no longer boot since the systemd-udevd service
> > failed to load.
> > 
> > My laptop runs systemd 242.
> > 
> > After removing the installed 50-rc_keymap.conf it worked again.
> > 
> > So either this file is no good, or it requires a newer systemd for it to
> > work.
> 
> I think I know what the problem is. On Fedora, for the systemd-udevd.service
> there is this setting.
> SystemCallFilter=@system-service @module @raw-io
> then 50-rc_keymap.conf adds:
> SystemCallFilter=bpf
> Which is concatenated to the end.
> 
> On the debian version of systemd, SystemCallFilter is not set. So
> SystemCallFilter=bpf
> means that only the bpf syscall is allowed. 
> 
> I'm not sure what the correct solution is. I'll try a few things and if I
> don't come up with anything, I'll have to revert.
> 
> Suggestions welcome :)

I think this could be solved by having configure check for SystemCallFilter,
like so:

	grep -s SystemCallFilter /lib/systemd/system/systemd-udevd.service 

and then installing the override if needed. I'll try to do this in the next
few days.

Thanks,
Sean
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index c84067ae..01a24a28 100644
--- a/configure.ac
+++ b/configure.ac
@@ -362,6 +362,11 @@  AC_ARG_WITH(udevdir,
    	[],
 	[with_udevdir=`$PKG_CONFIG --variable=udevdir udev || echo /lib/udev`])
 
+AC_ARG_WITH(systemdsystemunitdir,
+	AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [set systemd system unit directory]),
+	[],
+	[with_systemdsystemunitdir=`$PKG_CONFIG --variable=systemdsystemunitdir systemd || echo /lib/systemd/system`])
+
 # Generic check: works with most distributions
 def_gconv_dir=`for i in /lib64 /usr/lib64 /usr/local/lib64 /lib /usr/lib /usr/local/lib; do if @<:@ -d \$i/gconv @:>@; then echo \$i/gconv; break; fi; done`
 
@@ -384,6 +389,7 @@  AC_SUBST([libv4lconvertprivdir], [$libdir/$with_libv4lconvertsubdir])
 AC_SUBST([keytablesystemdir], [$with_udevdir/rc_keymaps])
 AC_SUBST([keytableuserdir], [$sysconfdir/rc_keymaps])
 AC_SUBST([udevrulesdir], [$with_udevdir/rules.d])
+AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir/systemd-udevd.service.d/])
 AC_SUBST([pkgconfigdir], [$libdir/pkgconfig])
 AC_SUBST([gconvsysdir], [$with_gconvdir])
 
diff --git a/utils/keytable/50-rc_keymap.conf b/utils/keytable/50-rc_keymap.conf
new file mode 100644
index 00000000..6066c50c
--- /dev/null
+++ b/utils/keytable/50-rc_keymap.conf
@@ -0,0 +1,3 @@ 
+# ir-keytable needs access to bpf in order load BPF decoders
+[Service]
+SystemCallFilter=bpf
diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index d7b30e2c..dfcd7609 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -3,6 +3,7 @@  man_MANS = ir-keytable.1 rc_keymap.5
 sysconf_DATA = rc_maps.cfg
 keytablesystem_DATA = $(srcdir)/rc_keymaps/*
 udevrules_DATA = 70-infrared.rules
+systemdsystemunit_DATA = 50-rc_keymap.conf
 
 ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h keymap.c keymap.h
 
@@ -18,7 +19,7 @@  ir_keytable_LDFLAGS += $(LIBELF_LIBS)
 SUBDIRS = bpf_protocols
 endif
 
-EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace gen_input_events.pl gen_keytables.pl ir-keytable.1 rc_maps.cfg rc_keymap.5
+EXTRA_DIST = 70-infrared.rules 50-rc_keymap.conf rc_keymaps rc_keymaps_userspace gen_input_events.pl gen_keytables.pl ir-keytable.1 rc_maps.cfg rc_keymap.5
 
 check:
 	@$(foreach keymap,$(wildcard $(keytablesystem_DATA)),./ir-keytable --test-keymap=$(keymap);)
diff --git a/v4l-utils.spec.in b/v4l-utils.spec.in
index d9d46706..a368d3fe 100644
--- a/v4l-utils.spec.in
+++ b/v4l-utils.spec.in
@@ -121,6 +121,7 @@  make doxygen-run
 
 %install
 %{!?_udevrulesdir: %global _udevrulesdir /lib/udev/rules.d}
+%{!?_systemdsystemunitdir: %global _systemdsystemunitdir /lib/systemd/system}
 %make_install
 find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
 rm -f $RPM_BUILD_ROOT%{_libdir}/{v4l1compat.so,v4l2convert.so}
@@ -142,6 +143,7 @@  desktop-file-validate $RPM_BUILD_ROOT%{_datadir}/applications/qv4l2.desktop
 %config(noreplace) %{_sysconfdir}/rc_maps.cfg
 %{_udevrulesdir}/70-infrared.rules
 %{_udevrulesdir}/../rc_keymaps/*
+%{_systemdsystemunitdir}/50-rc_keymap.conf
 %{_bindir}/cx18-ctl
 %{_bindir}/cec*
 %{_bindir}/dvb*