All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gert Doering <gert@...1296...>
To: Timo Rothenpieler <timo@...2669...>
Cc: openvpn-devel@lists.sourceforge.net, David Sommerseth <davids@...515...>
Subject: Re: [Openvpn-devel] [PATCH v3] platform: Retain CAP_NET_ADMIN when dropping privileges
Date: Fri, 8 Apr 2022 11:35:48 +0200	[thread overview]
Message-ID: <YlAB9NJWMd9H/EUg@...1296...> (raw)
In-Reply-To: <20220407184023.249-1-timo@...2669...>

[-- Attachment #1: Type: text/plain, Size: 2596 bytes --]

Hi,

On Thu, Apr 07, 2022 at 08:40:24PM +0200, Timo Rothenpieler wrote:
> +    else if (res < 0)
> +    {
> +        if (res == -3)
> +        {
> +            msg(M_NONFATAL, "Following error likely due to missing capability CAP_SETPCAP.");
> +        }
> +        msg(err_flags | M_ERRNO, "capng_change_id('%s','%s') failed retaining capabilities: %d",
> +            user_state->username, group_state->groupname, res);
> +        goto fallback;
> +    }

Wouldn't that overwrite errno for the "res == -3" case, given that
msg() will do stdio stuff?  Maybe reorder and print the "error likely due..."
message with a preceding "NOTE:" after the capng_change_id() message?

(That would be more typical for our logs - the "NOTE: this could be
because..." tends to come after the error message)

> +    if (new_uid >= 0)
> +    {
> +         msg(M_INFO, "UID set to %s", user_state->username);
> +    }
> +    if (new_gid >= 0)
> +    {
> +         msg(M_INFO, "GID set to %s", group_state->groupname);
> +    }
> +
> +    msg(M_INFO, "Capabilities retained: CAP_NET_ADMIN");
> +
> +    return;
> +fallback:

My inner whitespace dragon does would prefer to have the blank line
between "return" and "fallback:" (and no blank linke after the M_INFO).

> +    /* capng_change_id() can leave this flag clobbered on failure
> +     * This is working around a bug in libcap-ng, which can leave the flag set
> +     * on failure: https://github.com/stevegrubb/libcap-ng/issues/33 */
> +    if (prctl(PR_GET_KEEPCAPS) && prctl(PR_SET_KEEPCAPS, 0) < 0)
> +    {
> +        msg(M_ERR, "Clearing KEEPCAPS flag failed");
> +    }
> +#endif  /* HAVE_LIBCAPNG */

This one does not really look like it should be in "fallback:" - because
that way it always gets called, even if we jump there right at function
entry, if keep_caps == 0.

> +
> +    if (keep_caps)
> +    {
> +        msg(err_flags, "Unable to retain capabilities");
> +    }
> +
> +    platform_group_set(group_state);
> +    platform_user_set(user_state);
> +}
> +

Maybe "fallback:" should be right before platform_group_set()?


(Sorry for being late to the "complain about your code" party...)

gert
-- 
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             gert@...1296...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 630 bytes --]

  reply	other threads:[~2022-04-08  9:35 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 19:29 [Openvpn-devel] [PATCH] Retain CAP_NET_ADMIN when dropping privileges Timo Rothenpieler
2022-03-29 23:45 ` Timo Rothenpieler
2022-03-30  8:51 ` David Sommerseth
2022-03-30  9:11   ` David Sommerseth
2022-03-30 11:31     ` Timo Rothenpieler
2022-03-30 11:57       ` Gert Doering
2022-03-30 12:16         ` Antonio Quartulli
2022-03-30 15:05     ` Timo Rothenpieler
2022-03-30 20:55 ` [Openvpn-devel] [PATCH v2] " Timo Rothenpieler
2022-03-31  6:53   ` Jan Just Keijser
2022-03-31 10:06     ` David Sommerseth
2022-03-31 10:17       ` Arne Schwabe
2022-03-31 11:02       ` Gert Doering
2022-03-31 11:29         ` Timo Rothenpieler
2022-03-31 11:34           ` Gert Doering
2022-03-31 11:39             ` David Sommerseth
2022-03-31 13:20   ` David Sommerseth
2022-03-31 13:26     ` Gert Doering
2022-03-31 14:38       ` David Sommerseth
2022-03-31 14:54         ` Gert Doering
2022-04-06  9:52   ` Antonio Quartulli
2022-04-06 12:44     ` Timo Rothenpieler
2022-04-06 13:34       ` David Sommerseth
2022-04-06 13:41       ` David Sommerseth
2022-04-07 18:40   ` [Openvpn-devel] [PATCH v3] platform: " Timo Rothenpieler
2022-04-08  9:35     ` Gert Doering [this message]
2022-04-08 11:18       ` Timo Rothenpieler
2022-04-08 11:25         ` Antonio Quartulli
2022-04-18 13:29 ` [Openvpn-devel] [PATCH] " Timo Rothenpieler
2022-05-14 10:37 ` [Openvpn-devel] [PATCH v5] " Timo Rothenpieler
2022-08-10 13:57   ` Timo Rothenpieler
2022-08-11  9:30   ` Frank Lichtenheld
2022-08-11 10:03   ` [Openvpn-devel] [PATCH applied] " Gert Doering
2022-08-11 11:29     ` Gert Doering
2022-08-15  9:54     ` Gert Doering
2022-08-15 10:14       ` Timo Rothenpieler
2022-08-15 10:29         ` Gert Doering
2022-08-15 10:40           ` Timo Rothenpieler
2022-08-15 10:48             ` Gert Doering
2022-08-16  9:16               ` Steffan Karger
2022-08-16  9:33                 ` Gert Doering
2022-08-16  9:29       ` Gert Doering
2022-08-17 15:31       ` Gert Doering

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=YlAB9NJWMd9H/EUg@...1296... \
    --to=openvpn-devel@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.