Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Amish <anon.amish@gmail.com>
Cc: netfilter <netfilter@vger.kernel.org>
Subject: Re: iptables 1.8.8 fails with error code 111 but iptables 1.8.7 succeeds with same script
Date: Fri, 17 Jun 2022 17:09:31 +0200	[thread overview]
Message-ID: <20220617150931.GA19244@breakpoint.cc> (raw)
In-Reply-To: <f8b1ba7f-2d59-e068-92ca-a139959aa2fd@gmail.com>

Amish <anon.amish@gmail.com> wrote:
> I use Arch Linux. Apache 2.4.54 and iptables 1.8.8 (nft based).
> 
> I have a setuid script, given below, which runs via apache httpd and simply
> calls "iptables -w -nvL INPUT" and gives the output.
> 
> But with iptables 1.8.8 it fails with error code 111 (undocumented code)
> 
> > curl http://127.0.0.1/ipt.e
> EUID = 0, EGID=33
> iptables exited with exit code=111
> iptables exited with exit code=111

I plan to add this to the manual page:

iptables will exit immediately with an error code of 111 if it finds
that it was called as a setuid-to-root program.
iptables cannot be used safely in this manner because it trusts
the shared libraries (matches, targets) loaded at run time, the search
path can be set using environment variables.

> So it appears to be some kind of bug introduced in 1.8.8.

Its intentional.

> The C script follows: (Can be used for testing)
> int my_system(const char *program, char *const argv[])
> {
>     pid_t pid = fork();
>     if (pid==(pid_t)-1) return -1;
>     if (!pid) { execve(program, argv, environ); exit(127); }

iptables evaluates some environment variables and trusts that info.
If you absolutely have to do this, re-set environ so that someone
else calling this wrapper can't use it to load their own
modules/targets.

Then add a 'setuid(0)' before execve.

  parent reply	other threads:[~2022-06-17 15:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17 14:32 iptables 1.8.8 fails with error code 111 but iptables 1.8.7 succeeds with same script Amish
2022-06-17 14:56 ` Jeremy Sowden
2022-06-17 15:09 ` Florian Westphal [this message]
2022-06-18  5:27   ` Amish

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=20220617150931.GA19244@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=anon.amish@gmail.com \
    --cc=netfilter@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