From: Florian Westphal <fw@strlen.de>
To: Alan Ross <alan@sleuthco.ai>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] security: use secure_getenv() to prevent env-var privilege escalation
Date: Wed, 11 Feb 2026 20:03:45 +0100 [thread overview]
Message-ID: <aYzSkR0lrv8MIgg7@strlen.de> (raw)
In-Reply-To: <CAKgz23Hendu+Y=rhSwupr30Vf0JuJS5b6D-vp8A0TAC2swA-Bw@mail.gmail.com>
Alan Ross <alan@sleuthco.ai> wrote:
> The gap is when iptables is run with file capabilities rather than via
> sudo:
>
> setcap cap_net_admin+ep /usr/sbin/iptables
>
> In that case the kernel sets AT_SECURE, the linker correctly strips
> LD_PRELOAD, but getenv("XTABLES_LIBDIR") still
> returns the attacker-controlled value and gets passed to dlopen().
> secure_getenv() closes that specific gap.
>
> >> iptables requires CAP_NET_ADMIN to work and it was never designed to
> work with setuid-to-root.
>
> Understood. The capability-elevated case above is the primary scenario —
> some container runtimes and minimal
> distributions grant cap_net_admin via setcap rather than running through
> sudo, and that's where the env-controlled
> dlopen() becomes reachable.
ARGH!
cd ~/git/iproute2
git grep getenv | wc -l
36
> That said, I recognize this is defense-in-depth rather than a critical
> fix. secure_getenv() is a strict behavioral
> superset of getenv() for unprivileged execution (returns the same value
> when euid==uid), so the patch has no impact on
> normal usage. The precedent is util-linux (su, mount) and sudo, which
> made the same change for similar env-controlled
> paths.
>
> If the consensus is that capability-elevated iptables is not a supported
> configuration, I understand. Happy to drop
> the patch or adjust scope.
If there are distros that are dumb enough to setuid-to-0/setcap random
binaries then we should cope with this.
Would you have the cycles to go through all of nf software to make this
change? nftables, ipet, conntrack, ulogd etc would all need this
change. And non-netfilter software too, iproute2 tool has 36 getenv
calls.
As for this patch, I think it just needs a rework of the commit message
to explain that this is about existing distros/containers that setcap the
binary.
Any reason for the wrapper to not do
static inline const char *secure_getenv(const char *name)
{
unsigned long x = getauxval(AT_SECURE);
return x == 0 ? getenv(name) : NULL
}
?
It probably doesn't matter too much given glibc 2.17 is ancient, but
still, I'm curious.
Another option is to alter ef7781eb1437a2d6fd37eb3567c599e3ea682b96
("libxtables: exit if called by setuid executeable")
to enforce non-capability binary and then followup in nftables and
others.
next prev parent reply other threads:[~2026-02-11 19:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 14:19 [PATCH] security: use secure_getenv() to prevent env-var privilege escalation Alan Ross
2026-02-11 17:06 ` Florian Westphal
[not found] ` <CAKgz23Hendu+Y=rhSwupr30Vf0JuJS5b6D-vp8A0TAC2swA-Bw@mail.gmail.com>
2026-02-11 19:03 ` Florian Westphal [this message]
[not found] ` <CAKgz23GWzqiryJwfjJyf7ObTkAnLciFZ6vKXcxACtm-N8xZi-w@mail.gmail.com>
2026-02-12 0:18 ` Florian Westphal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aYzSkR0lrv8MIgg7@strlen.de \
--to=fw@strlen.de \
--cc=alan@sleuthco.ai \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox