From patchwork Thu Oct 20 22:10:14 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: 120913 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 A17E71007D1 for ; Fri, 21 Oct 2011 09:10:30 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751003Ab1JTWKZ (ORCPT ); Thu, 20 Oct 2011 18:10:25 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:61550 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927Ab1JTWKZ (ORCPT ); Thu, 20 Oct 2011 18:10:25 -0400 Received: by yxl42 with SMTP id 42so710929yxl.19 for ; Thu, 20 Oct 2011 15:10:24 -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=9NI6CvlQZ8JxsP4ObC4faPwGnCib14bZJ8rJ1CgwXlg=; b=FLpN/6aLKoXwvgOMAxWt0rmH2ul5EbzL02/s3SDV2j7yQjB5ZwScYV6gcvmYcDabSd 1MV4JOAe1DqMjswYuGGD6giQIcK0mkxlvMHWXo0IM9F+ofNkAfQ5Gylm625cbhpttAQT OTCpqjXbaEjI3pEtbcMaX+SdavtbbCsz9EquQ= Received: by 10.68.31.41 with SMTP id x9mr5811934pbh.102.1319148624361; Thu, 20 Oct 2011 15:10:24 -0700 (PDT) Received: from localhost.localdomain (sugar.mtv.corp.google.com [172.22.97.53]) by mx.google.com with ESMTPS id h5sm23030998pbq.11.2011.10.20.15.10.23 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Oct 2011 15:10:23 -0700 (PDT) From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= To: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Cc: David Miller , netdev@vger.kernel.org, =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Subject: [PATCH] net: allow CAP_NET_RAW to set socket options IP{, V6}_TRANSPARENT Date: Thu, 20 Oct 2011 15:10:14 -0700 Message-Id: <1319148614-6739-1-git-send-email-zenczykowski@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <20111020.003458.1034042223691970343.davem@davemloft.net> References: <20111020.003458.1034042223691970343.davem@davemloft.net> 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 allow CAP_NET_ADMIN to set the bit (as before this change) - we allow CAP_NET_RAW to set this bit, because raw sockets already pretty much effectively allow you to emulate socket transparency. Signed-off-by: Maciej Żenczykowski --- include/linux/capability.h | 3 ++- net/ipv4/ip_sockglue.c | 2 +- net/ipv6/ipv6_sockglue.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/capability.h b/include/linux/capability.h index c421123..a63d13d 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 (also via NET_RAW) */ /* 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 (also via NET_ADMIN) */ #define CAP_NET_RAW 13 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 8905e92..f0dc3ad 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -961,7 +961,7 @@ mc_msf_out: break; case IP_TRANSPARENT: - if (!capable(CAP_NET_ADMIN)) { + if (!!val && !capable(CAP_NET_RAW) && !capable(CAP_NET_ADMIN)) { err = -EPERM; break; } diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 2fbda5f..c99e3ee 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -343,7 +343,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, break; case IPV6_TRANSPARENT: - if (!capable(CAP_NET_ADMIN)) { + if (valbool && !capable(CAP_NET_ADMIN) && !capable(CAP_NET_RAW)) { retv = -EPERM; break; }