[systemd-devel] [RFC][PATCH 1/2] resolve: resolved-manager: Avoid null dereference

Tom Gundersen teg at jklm.no
Wed Oct 22 13:12:07 PDT 2014


On Wed, Oct 22, 2014 at 12:19 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> On Sat, 13.09.14 20:40, Tom Gundersen (teg at jklm.no) wrote:
>
>> Yeah, this could happen. It so happens that the loopback link will
>> always have ifindex 1, so I guess we could just fall back to checking
>> for that if we don't have the real flags.
>
> Is that true even in network namespaces? Is this really exported API?
> I really don't want to rely on behaviour here that is not considered
> official API of Linux.
>
> If it is safe API of Linux, then we really should drop
> manager_ifindex_is_loopback() entirely, and just always compare the
> ifindex.
>
> Anyone has some pointers where this is made API?

We may want to ask the kernel guys to export LOOPBACK_IFINDEX, as it
is not at the moment. However, I think relying on it is fine even
without that as the kernel will BUG_ON if "lo" does not have ifindex
1[0], and no other netdev can have ifindex 1[1]:

        /* The loopback device is special if any other network devices
         * is present in a network namespace the loopback device must
         * be present.

Changing these invariants would surely break lots of stuff, so cannot happen.

I'd be happy to push for this to be made explicit though.

Cheers,

Tom

[0]: <https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/net/loopback.c#n207>
[1]: <https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/net/core/dev.c#n7260>


More information about the systemd-devel mailing list