Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp778689ybb; Wed, 1 Apr 2020 09:27:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuu+b8piUIACvq5QIMnDpV9YZbH+FoO6AqziwfWsMc8QltQRdqR0d/tSWjeeyDqg6c/kgKg X-Received: by 2002:a9d:5545:: with SMTP id h5mr18099538oti.323.1585758435315; Wed, 01 Apr 2020 09:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585758435; cv=none; d=google.com; s=arc-20160816; b=0EdunVbAah4qOkckwo1IFqy95SxXc51aysVEyBpFwTumWWc+LlpD2ibdb+f+3iaqG1 DNg86i2bApT7PjhAsumQyuNCItw+B7qOMoTl5ZhCbLGsuu/WpV089ot8pSA5utAnp1YV 9IgrvCPnzpgjQPQwY5CMBOJr6wQOWmesfDNNvE99TYzeaCuqko/Jpoy2NwBMhAuJr5Lp 80jmHo6IJGt10+LegO2ZqiR1zQ7/OIEEPCphjJiOLAgIxRDxtr64c8GnURzOa71vTdvT qWYoCDydzjSfY94HMfNNzvyrvE4vdwhj5oW6lM/gk2XAdmbSH3icvyrbQsqkbfTT93hg +teg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=afCtQFea5GYE0TNNOsCjhYebQ24zAh+Uc3/itnR0pXo=; b=R+6eUD/UAO1yllA7CNvqhcc7jT0PJgM+5FImcciwmiVBKYRUcVLZyjnJnE/z1sjLor VW2XAZw4hEP91+QgCe1BBVx4/r8sKD8PtcGU41T1Cpgjd/X0xjO7Uq2FQNuZu8YHCKFB qvfYm6fsesO5P59YEcoyuEICasQ7cNYP3hrUdRTDy0anhmWwhuJdIzDlJuNGg2MgcWLW kZ4eZmFIZDauMWZA76uqjSufqm9D3Ovnb0F1R6rbY7MfTqCQgDFW8vO+JxJiL94kwxEM 49kv2QW924H7yymOS9VlFFTyEoDn05KX+pdlzKnjSLdFcKxrb0GCPs0JiB5wbLtqmVvV dV+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FFkb+YYE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5si973478ood.66.2020.04.01.09.27.02; Wed, 01 Apr 2020 09:27:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FFkb+YYE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732286AbgDAQZz (ORCPT + 99 others); Wed, 1 Apr 2020 12:25:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:50240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733248AbgDAQZx (ORCPT ); Wed, 1 Apr 2020 12:25:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9BE3120857; Wed, 1 Apr 2020 16:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585758352; bh=XIYBtugiasciTP7u20DZyWOD6PmoGbNI6j6p7zPtfes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FFkb+YYE3bhQwhtrzWxhOUsy4QHwUztQJOUgUFSjYlQRKZ94Y3ennIFy1kraEI0QP vwcOJCRuIqyAzGfB6bw9OAGPqFQrKHG5tKoJ7hTuvmjyIGKQTr7+nPKNBUF8CexXV0 01DfIaZQhMelNpXoBvCJM6tCwNP6rrEMs00Se8Wg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kaike Wan , Mike Marciniszyn , Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 4.19 063/116] RDMA/core: Ensure security pkey modify is not lost Date: Wed, 1 Apr 2020 18:17:19 +0200 Message-Id: <20200401161551.604315091@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161542.669484650@linuxfoundation.org> References: <20200401161542.669484650@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Marciniszyn commit 2d47fbacf2725a67869f4d3634c2415e7dfab2f4 upstream. The following modify sequence (loosely based on ipoib) will lose a pkey modifcation: - Modify (pkey index, port) - Modify (new pkey index, NO port) After the first modify, the qp_pps list will have saved the pkey and the unit on the main list. During the second modify, get_new_pps() will fetch the port from qp_pps and read the new pkey index from qp_attr->pkey_index. The state will still be zero, or IB_PORT_PKEY_NOT_VALID. Because of the invalid state, the new values will never replace the one in the qp pps list, losing the new pkey. This happens because the following if statements will never correct the state because the first term will be false. If the code had been executed, it would incorrectly overwrite valid values. if ((qp_attr_mask & IB_QP_PKEY_INDEX) && (qp_attr_mask & IB_QP_PORT)) new_pps->main.state = IB_PORT_PKEY_VALID; if (!(qp_attr_mask & (IB_QP_PKEY_INDEX | IB_QP_PORT)) && qp_pps) { new_pps->main.port_num = qp_pps->main.port_num; new_pps->main.pkey_index = qp_pps->main.pkey_index; if (qp_pps->main.state != IB_PORT_PKEY_NOT_VALID) new_pps->main.state = IB_PORT_PKEY_VALID; } Fix by joining the two if statements with an or test to see if qp_pps is non-NULL and in the correct state. Fixes: 1dd017882e01 ("RDMA/core: Fix protection fault in get_pkey_idx_qp_list") Link: https://lore.kernel.org/r/20200313124704.14982.55907.stgit@awfm-01.aw.intel.com Reviewed-by: Kaike Wan Signed-off-by: Mike Marciniszyn Reviewed-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/security.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- a/drivers/infiniband/core/security.c +++ b/drivers/infiniband/core/security.c @@ -346,16 +346,11 @@ static struct ib_ports_pkeys *get_new_pp else if (qp_pps) new_pps->main.pkey_index = qp_pps->main.pkey_index; - if ((qp_attr_mask & IB_QP_PKEY_INDEX) && (qp_attr_mask & IB_QP_PORT)) + if (((qp_attr_mask & IB_QP_PKEY_INDEX) && + (qp_attr_mask & IB_QP_PORT)) || + (qp_pps && qp_pps->main.state != IB_PORT_PKEY_NOT_VALID)) new_pps->main.state = IB_PORT_PKEY_VALID; - if (!(qp_attr_mask & (IB_QP_PKEY_INDEX | IB_QP_PORT)) && qp_pps) { - new_pps->main.port_num = qp_pps->main.port_num; - new_pps->main.pkey_index = qp_pps->main.pkey_index; - if (qp_pps->main.state != IB_PORT_PKEY_NOT_VALID) - new_pps->main.state = IB_PORT_PKEY_VALID; - } - if (qp_attr_mask & IB_QP_ALT_PATH) { new_pps->alt.port_num = qp_attr->alt_port_num; new_pps->alt.pkey_index = qp_attr->alt_pkey_index;