From patchwork Thu Aug 6 21:08:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 6963051 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8C13F9F38B for ; Thu, 6 Aug 2015 21:08:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2B4E2060C for ; Thu, 6 Aug 2015 21:08:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B33E7205FA for ; Thu, 6 Aug 2015 21:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755662AbbHFVIu (ORCPT ); Thu, 6 Aug 2015 17:08:50 -0400 Received: from mga11.intel.com ([192.55.52.93]:51060 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754381AbbHFVIt (ORCPT ); Thu, 6 Aug 2015 17:08:49 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 06 Aug 2015 14:08:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,625,1432623600"; d="scan'208";a="537346469" Received: from phlsvsds.ph.intel.com ([10.228.195.38]) by FMSMGA003.fm.intel.com with ESMTP; 06 Aug 2015 14:08:49 -0700 Received: from phlsvsds.ph.intel.com (localhost.localdomain [127.0.0.1]) by phlsvsds.ph.intel.com (8.13.8/8.13.8) with ESMTP id t76L8m5S007335; Thu, 6 Aug 2015 17:08:48 -0400 Received: (from iweiny@localhost) by phlsvsds.ph.intel.com (8.13.8/8.13.8/Submit) id t76L8lI5007332; Thu, 6 Aug 2015 17:08:47 -0400 X-Authentication-Warning: phlsvsds.ph.intel.com: iweiny set sender to ira.weiny@intel.com using -f From: ira.weiny@intel.com To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, Ira Weiny Subject: [PATCH] IB/sa: Restrict SA Netlink to admin users Date: Thu, 6 Aug 2015 17:08:30 -0400 Message-Id: <1438895310-6087-1-git-send-email-ira.weiny@intel.com> X-Mailer: git-send-email 1.7.1 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ira Weiny The recently added SA Netlink service requires admin privileges to receive kernel requests. This is only partially sufficient to protect the kernel from malicious users. This patch fixes two issues. 1) Path responses from user space could be spoofed if the sequence number was properly guessed. 2) The set timeout request message could be issued by any user. Ignore these messages if not submitted by an admin user. Fixes: 6619209af36c ("IB/sa: Route SA pathrecord query through netlink") Signed-off-by: Ira Weiny --- Doug let me know if you would prefer that I get Kaike to squash this into the original patch. drivers/infiniband/core/sa_query.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c index 70ceec4df02a..52be6d71b2f4 100644 --- a/drivers/infiniband/core/sa_query.c +++ b/drivers/infiniband/core/sa_query.c @@ -49,6 +49,7 @@ #include #include #include +#include #include "sa.h" MODULE_AUTHOR("Roland Dreier"); @@ -699,6 +700,12 @@ static int ib_nl_handle_set_timeout(struct sk_buff *skb, struct nlattr *tb[LS_NLA_TYPE_MAX + 1]; int ret; + if (!ns_capable(sock_net(skb->sk)->user_ns, CAP_NET_ADMIN)) { + pr_warn_ratelimited("SA netlink: invalid perm for set timeout: `%s'.\n", + current->comm); + return -EPERM; + } + ret = nla_parse(tb, LS_NLA_TYPE_MAX, nlmsg_data(nlh), nlmsg_len(nlh), NULL); attr = (const struct nlattr *)tb[LS_NLA_TYPE_TIMEOUT]; @@ -706,6 +713,9 @@ static int ib_nl_handle_set_timeout(struct sk_buff *skb, goto settimeout_out; timeout = *(int *) nla_data(attr); + + pr_info("SA netlink: timeout: %d\n", timeout); + if (timeout < IB_SA_LOCAL_SVC_TIMEOUT_MIN) timeout = IB_SA_LOCAL_SVC_TIMEOUT_MIN; if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX) @@ -754,6 +764,12 @@ static int ib_nl_handle_resolve_resp(struct sk_buff *skb, int found = 0; int ret; + if (!ns_capable(sock_net(skb->sk)->user_ns, CAP_NET_ADMIN)) { + pr_warn_ratelimited("SA netlink: invalid perm for response: `%s'.\n", + current->comm); + return -EPERM; + } + spin_lock_irqsave(&ib_nl_request_lock, flags); list_for_each_entry(query, &ib_nl_request_list, list) { /* @@ -770,6 +786,7 @@ static int ib_nl_handle_resolve_resp(struct sk_buff *skb, if (!found) { spin_unlock_irqrestore(&ib_nl_request_lock, flags); + pr_err_ratelimited("SA netlink: got unmatched response\n"); goto resp_out; }