UPSTREAM: netfilter: Allow xt_owner in any user namespace

Making this work is a little tricky as it really isn't kosher to
change the xt_owner_match_info in a check function.

Without changing xt_owner_match_info we need to know the user
namespace the uids and gids are specified in.  In the common case
net->user_ns == current_user_ns().  Verify net->user_ns ==
current_user_ns() in owner_check so we can later assume it in
owner_mt.

In owner_check also verify that all of the uids and gids specified are
in net->user_ns and that the expected min/max relationship exists
between the uids and gids in xt_owner_match_info.

In owner_mt get the network namespace from the outgoing socket, as this
must be the same network namespace as the netfilter rules, and use that
network namespace to find the user namespace the uids and gids in
xt_match_owner_info are encoded in.  Then convert from their encoded
from into the kernel internal format for uids and gids and perform the
owner match.

Similar to ping_group_range, this code does not try to detect
noncontiguous UID/GID ranges.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
(cherry picked from commit 9847371a84b0be330f4bc4aaa98904101ee8573d,
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git)
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>

BUG=b:29161036
BUG=b:29554103
TEST=`/system/bin/iptables -w -A fw_dozable -m owner --uid-owner 0 -j RETURN`
     run from android-sh root shell

Change-Id: If46d77874caa7cac5000471114bce247e43ec78f
Reviewed-on: https://chromium-review.googlesource.com/356863
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Guenter Roeck <groeck@google.com>
1 file changed