From patchwork Mon Oct 17 22:16:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Maciej_=C5=BBenczykowski?= X-Patchwork-Id: 120307 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 229F0B6F90 for ; Tue, 18 Oct 2011 09:16:47 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753015Ab1JQWQk (ORCPT ); Mon, 17 Oct 2011 18:16:40 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:49811 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751414Ab1JQWQj (ORCPT ); Mon, 17 Oct 2011 18:16:39 -0400 Received: by ywf7 with SMTP id 7so1096858ywf.19 for ; Mon, 17 Oct 2011 15:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=Pe0oh0hocKefyGrI68O1+kgHSWO/X/RTgUpCT8qXGYs=; b=k1wwCE1O0+xtpuDljtFEo/XGKibNqOo8g2yWGydedBUYgmK8CDhYiSabo1kS/o3sBk TL/paOwEx0OD8r6Q3iImmbfu47/3CjN93G70K5ggHLFu2OCYpCJP03vkkk02FnfCWePA mIITTAkZPA9uXQUVFeD9RkYm8w9ksAsHZ/h34= Received: by 10.68.12.138 with SMTP id y10mr9084pbb.70.1318889798913; Mon, 17 Oct 2011 15:16:38 -0700 (PDT) Received: from localhost.localdomain (sugar.mtv.corp.google.com [172.22.97.53]) by mx.google.com with ESMTPS id h5sm249461pbq.11.2011.10.17.15.16.35 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Oct 2011 15:16:35 -0700 (PDT) From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= To: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Cc: netdev@vger.kernel.org, Balazs Scheidler , =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Subject: [PATCH] net: change capability used by socket options IP{, V6}_TRANSPARENT Date: Mon, 17 Oct 2011 15:16:23 -0700 Message-Id: <1318889783-23183-1-git-send-email-zenczykowski@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <20110920.154213.888729603269720228.davem@redhat.com> References: <20110920.154213.888729603269720228.davem@redhat.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Maciej Żenczykowski Up till now the IP{,V6}_TRANSPARENT socket options (which actually set the same bit in the socket struct) have required CAP_NET_ADMIN privileges to set or clear the option. - we make clearing the bit not require any privileges. - we deprecate using CAP_NET_ADMIN for this purpose. - we allow CAP_NET_RAW to set this bit, because raw sockets already effectively allow you to emulate socket transparency. - we print a warning (but allow it) if you try to set the socket option with CAP_NET_ADMIN privs, but without CAP_NET_RAW. Signed-off-by: Maciej Żenczykowski --- include/linux/capability.h | 3 ++- net/ipv4/ip_sockglue.c | 20 ++++++++++++++++---- net/ipv6/ipv6_sockglue.c | 23 ++++++++++++++++++----- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/linux/capability.h b/include/linux/capability.h index c421123..ce34ae3 100644 --- a/include/linux/capability.h +++ b/include/linux/capability.h @@ -198,7 +198,7 @@ struct cpu_vfs_cap_data { /* Allow modification of routing tables */ /* Allow setting arbitrary process / process group ownership on sockets */ -/* Allow binding to any address for transparent proxying */ +/* Allow binding to any address for transparent proxying (deprecated) */ /* Allow setting TOS (type of service) */ /* Allow setting promiscuous mode */ /* Allow clearing driver statistics */ @@ -210,6 +210,7 @@ struct cpu_vfs_cap_data { /* Allow use of RAW sockets */ /* Allow use of PACKET sockets */ +/* Allow binding to any address for transparent proxying */ #define CAP_NET_RAW 13 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 8905e92..74f7d30 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -961,12 +961,24 @@ mc_msf_out: break; case IP_TRANSPARENT: - if (!capable(CAP_NET_ADMIN)) { - err = -EPERM; - break; - } if (optlen < 1) goto e_inval; + /* Always allow clearing the transparent proxy socket option. + * The pre-3.2 permission for setting this was CAP_NET_ADMIN, + * and this is still supported - but deprecated. As of Linux + * 3.2 the proper permission is CAP_NET_RAW. + */ + if (!!val && !capable(CAP_NET_RAW)) { + if (!capable(CAP_NET_ADMIN)) { + err = -EPERM; + break; + } + printk_once(KERN_WARNING "%s (%d): " + "deprecated: attempt to set socket option " + "IP_TRANSPARENT with CAP_NET_ADMIN but " + "without CAP_NET_RAW.\n", + current->comm, task_pid_nr(current)); + } inet->transparent = !!val; break; diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 2fbda5f..7c4f5ce 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -343,13 +343,26 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, break; case IPV6_TRANSPARENT: - if (!capable(CAP_NET_ADMIN)) { - retv = -EPERM; - break; - } if (optlen < sizeof(int)) goto e_inval; - /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ + /* Always allow clearing the transparent proxy socket option. + * The pre-3.2 permission for setting this was CAP_NET_ADMIN, + * and this is still supported - but deprecated. As of Linux + * 3.2 the proper permission is CAP_NET_RAW. + */ + if (valbool && !capable(CAP_NET_RAW)) { + if (!capable(CAP_NET_ADMIN)) { + retv = -EPERM; + break; + } + printk_once(KERN_WARNING "%s (%d): " + "deprecated: attempt to set socket option " + "IPV6_TRANSPARENT with CAP_NET_ADMIN but " + "without CAP_NET_RAW.\n", + current->comm, task_pid_nr(current)); + } + /* we don't have a separate transparent bit for IPv6, + * so we just use the one in the IPv4 socket */ inet_sk(sk)->transparent = valbool; retv = 0; break;