Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3289327ybb; Tue, 31 Mar 2020 02:11:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsQB4IQRc3WXCs7M/0/cRyfH7CeOEq33xnUuU5sovj93GTL3fF0RjxY2qFbNmGBvj3RXIV/ X-Received: by 2002:aca:b308:: with SMTP id c8mr1416372oif.131.1585645878706; Tue, 31 Mar 2020 02:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645878; cv=none; d=google.com; s=arc-20160816; b=XB9A5GLsFab2iFRBGZ10e7LOwT5JNiQsSMAoT4sIDGo0iX58nqWKtSFQz2EWoWJQRX y7A6wI9BHE5ajbksbX5VsRGddwYXlUY/h6WuUpzjBDPt2Z5UbrRVmSRUgW4NmTgfZ0dQ /+ee/KbKHg1IMb9pXFisB6Np0to/HNP12REWP69l4f6MchlfLM9JaoYNgj7FU3K+oHb1 UdAq8RtEVMPY3Q2YAtBuyr7vOvSMWSRjLSvP6f4p6RLUGUzHFUMb4ejguV0JpvawKlfo VVobPPzz90NVCWGgUdmZEUYNFAn9LyZ6fqvyaxTvoQtAVsEExyaw9ced+tdLSPelVCH6 RAdQ== 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=5aSUcgiUSW+ZPirdbFvg8TVlPlhKkRNI02VQvJ7JC/o=; b=cLmXzUGydURJoad9w/NKmMpvM4T2JOGYNvczkRAac4DcUg7Sj+rp0kyWGVTppBLG/N 2TzWqUECq36hssxI01VJEMUD2BRqXaub2B8m67ETf4d/Y2qBveZvfW8YCfWSJur+4zyo 8OG47JnHuhY8MDLafGlWyWTNAYH12DYi2cNpl6p1DLXf+os6SUZ5LrpoEKPU4pTpX5X8 yV6fA9q1Hg2/VPwLK5gQ2c+SbOiaL0aDgCR3FbRFGwwQ3ijcoLewE6se9IXf9VgAfUKl 0+CrNzzx8IyxTLlFJBPRLIjs7auiWBuBGs80kd4VvAEsO41C9XiBCLWEsSHeQhmy9EBa km3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AIUu0vQE; 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 z3si7791881oth.163.2020.03.31.02.11.04; Tue, 31 Mar 2020 02:11:18 -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=AIUu0vQE; 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 S1731493AbgCaJJi (ORCPT + 99 others); Tue, 31 Mar 2020 05:09:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:52696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731240AbgCaJJd (ORCPT ); Tue, 31 Mar 2020 05:09:33 -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 45B0320675; Tue, 31 Mar 2020 09:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645772; bh=MuJR827GwbcbpjRRdpPKWhk51Tk5Sf/7WcpNL6TTU6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIUu0vQEVqHzZeCf/5zK3UbVEnCG6lJuLyftwmS/GUX1zb2uUpaImMRQuN7R5WqXD iGX1Qezfsngk9bZXcxNYR+KcaFpwHeT7eC67uOhNWDDrE4qciOCBcaTw/IdBRx+m5m ZYMEHVy9pwhQ/0QqWXDSPuw4+RsNIrYhQ+z29tsw= 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 5.5 119/170] RDMA/core: Ensure security pkey modify is not lost Date: Tue, 31 Mar 2020 10:58:53 +0200 Message-Id: <20200331085436.749272127@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@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 @@ -349,16 +349,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;