From patchwork Mon Jun 5 10:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13267190 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7325FC7EE24 for ; Mon, 5 Jun 2023 10:34:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232040AbjFEKe1 (ORCPT ); Mon, 5 Jun 2023 06:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232054AbjFEKeS (ORCPT ); Mon, 5 Jun 2023 06:34:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F57135 for ; Mon, 5 Jun 2023 03:34:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2679A60F07 for ; Mon, 5 Jun 2023 10:34:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25D86C433EF; Mon, 5 Jun 2023 10:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685961247; bh=QpFFFlNxWIcnRDAY9hU4W8LNXtFoBTcdlUBVKXO9wm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0CJerbs96eQyyIk5H49BEopjxL74M2Obqei5ILI5uSo2pTqF9d+amUXD9TIvPjin wXgLq2RJ8NxCdNydgxst47i0r35kwf9thX+AwsecesydMQA/ED+nxJra99PXfeD1fL OSRt3mOBTUacbekK2+xTZhXgFEzKiLI7pGcKQ1J2vYaGqazih6XUIiFytrsVngKU6y AOJ68CNHoGBMtVpzFbOHdsLQFFTPmEBry73BjtTDH2WzAKjXQdvkrjD42kPESreJ0h 07f9HYOIy/vU4r/LuYnrmWc0do/zYaPS68+f2yLhYTpj+3e0ArPScI/iFkDP8vORXA /tNsX1hR92RDg== From: Leon Romanovsky To: Jason Gunthorpe Cc: Edward Srouji , linux-rdma@vger.kernel.org Subject: [PATCH rdma-rc 08/10] RDMA/uverbs: Restrict usage of privileged QKEYs Date: Mon, 5 Jun 2023 13:33:24 +0300 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Edward Srouji According to the IB specification rel-1.6, section 3.5.3: "QKEYs with the most significant bit set are considered controlled QKEYs, and a HCA does not allow a consumer to arbitrarily specify a controlled QKEY." Thus, block non-privileged users from setting such a QKEY. Fixes: bc38a6abdd5a ("[PATCH] IB uverbs: core implementation") Signed-off-by: Edward Srouji Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/uverbs_cmd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 4796f6a8828c..e836c9c477f6 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -1850,8 +1850,13 @@ static int modify_qp(struct uverbs_attr_bundle *attrs, attr->path_mtu = cmd->base.path_mtu; if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE) attr->path_mig_state = cmd->base.path_mig_state; - if (cmd->base.attr_mask & IB_QP_QKEY) + if (cmd->base.attr_mask & IB_QP_QKEY) { + if (cmd->base.qkey & IB_QP_SET_QKEY && !capable(CAP_NET_RAW)) { + ret = -EPERM; + goto release_qp; + } attr->qkey = cmd->base.qkey; + } if (cmd->base.attr_mask & IB_QP_RQ_PSN) attr->rq_psn = cmd->base.rq_psn; if (cmd->base.attr_mask & IB_QP_SQ_PSN)