Skip to content

units: systemd-udevd: add AF_INET to RestrictAddressFamilies=#4296

Merged
poettering merged 1 commit intosystemd:masterfrom
yuwata:fix-4293
Oct 6, 2016
Merged

units: systemd-udevd: add AF_INET to RestrictAddressFamilies=#4296
poettering merged 1 commit intosystemd:masterfrom
yuwata:fix-4293

Conversation

@yuwata
Copy link
Member

@yuwata yuwata commented Oct 6, 2016

The udev builtin command net_setup_link calls
socket(PF_INET, SOCK_DGRAM, 0) in ethtool-util.c.
So, the command requires AF_INET.

Fixes #4293.

@yuwata
Copy link
Member Author

yuwata commented Oct 6, 2016

I think the second paragraph of the following entry in NEWS needs to be removed or updated.

    * Various systemd services have been hardened with
      ProtectKernelTunables=yes, ProtectControlGroups=yes,
      RestrictAddressFamilies=.

      In particular, systemd-udevd.service is now run in a Seccomp-based
      sandbox that prohibits access to AF_INET and AF_INET6 sockets and
      thus access to the network. This might break code that runs from udev
      rules that tries to talk to the network. Doing that is generally a
      bad idea and unsafe due to a variety of reasons. It's also racy as
      device management would race against network configuration. It is
      recommended to rework such rules to use the SYSTEMD_WANTS property on
      the relevant devices to pull in a proper systemd service (which can
      be sandboxed differently and ordered correctly after the network
      having come up). If that's not possible consider reverting this
      sandboxing feature locally by removing the RestrictAddressFamilies=
      setting from the systemd-udevd.service unit file, or adding AF_INET
      and AF_INET6 to it.

@evverx
Copy link
Contributor

evverx commented Oct 6, 2016

I'm reading http://git.kernel.org/cgit/network/ethtool/ethtool.git/tree/NEWS

  • Feature: Use netlink socket when AF_INET not available

http://git.kernel.org/cgit/network/ethtool/ethtool.git/tree/ethtool.c?id=9674a827b9baf1503a69dd91b7981a163bd45e77#n4769

                /* Open control socket. */
                ctx.fd = socket(AF_INET, SOCK_DGRAM, 0);
                if (ctx.fd < 0)
                        ctx.fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
                if (ctx.fd < 0) {
                        perror("Cannot get control socket");
                        return 70;
                }

Shouldn't we do the same?

@evverx
Copy link
Contributor

evverx commented Oct 6, 2016

Shouldn't we do the same?

Well, this is a new feature: torvalds/linux@025c68186e07
So, this doesn't fix #4293 on older kernels.

@evverx
Copy link
Contributor

evverx commented Oct 6, 2016

So, we allow AF_INET. Why not to allow AF_INET6 too?

@poettering
Copy link
Member

So, we allow AF_INET. Why not to allow AF_INET6 too?

Yupp, I figure you are right: if we block AF_INET we should also block AF_INET6, and if we do not block either, we should not block the other either. They should always come in a pair I guess.

@yuwata can you rework the patch to also unblock AF_INET6 hence? Also, please drop the NEWS blurb that's out-of-date now from the file, in the same commit.

I think we should probably also implement the logic @evverx suggested (i.e. falling back to AF_NETLINK if AF_INET is not available for the interface ioctls everywhere). Even if it only works on new kernels for now I think it's in the long run the better choice. However, this change can be done later, as it doesn't fix anything...

…lies=

The udev builtin command `net_setup_link` requires AF_INET and AF_INET6.

Fixes systemd#4293.
@yuwata
Copy link
Member Author

yuwata commented Oct 6, 2016

Force pushed updated version. Thank you.

@poettering poettering merged commit 94f42fe into systemd:master Oct 6, 2016
@poettering poettering added the udev label Oct 6, 2016
poettering added a commit to poettering/systemd that referenced this pull request Oct 6, 2016
…tls on

As suggested here:

systemd#4296 (comment)

Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that
we can use a protocol-independent socket here if possible. This has the benefit
that our code will still work even if AF_INET/AF_INET6 is made available (for
exmple via seccomp), at least on current kernels.
poettering added a commit to poettering/systemd that referenced this pull request Oct 6, 2016
…tls on

As suggested here:

systemd#4296 (comment)

Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that
we can use a protocol-independent socket here if possible. This has the benefit
that our code will still work even if AF_INET/AF_INET6 is made available (for
exmple via seccomp), at least on current kernels.
poettering added a commit to poettering/systemd that referenced this pull request Oct 6, 2016
…tls on

As suggested here:

systemd#4296 (comment)

Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that
we can use a protocol-independent socket here if possible. This has the benefit
that our code will still work even if AF_INET/AF_INET6 is made unavailable (for
exmple via seccomp), at least on current kernels.
@yuwata yuwata deleted the fix-4293 branch October 11, 2016 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants