From patchwork Wed Apr 4 03:07:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10322015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 282A360116 for ; Wed, 4 Apr 2018 03:08:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15CFF23F88 for ; Wed, 4 Apr 2018 03:08:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A40024B44; Wed, 4 Apr 2018 03:08:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39FB723F88 for ; Wed, 4 Apr 2018 03:08:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753340AbeDDDH7 (ORCPT ); Tue, 3 Apr 2018 23:07:59 -0400 Received: from mail-he1eur01on0045.outbound.protection.outlook.com ([104.47.0.45]:10368 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753328AbeDDDH6 (ORCPT ); Tue, 3 Apr 2018 23:07:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=c/vei8IwdyykdJ4pZ81CnsIeKJOEta0jOyGZbL6ZblA=; b=S9dwX98WEcO7LkwLpt+forEPsVHvW5in/ovvq8XWfyVilmJyCHEzcY4nvvQJ7gOfN9dexbVY29nVFTDCeaFgxF1TVHzsjanSLOqcjTuBDJJ/40k42Fb5rBiP3/vJUyKPsrD6XblEVD0u/iSOIPUE5DN9VTJlSv+qoHoKDY9rN/Q= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jgg@mellanox.com; Received: from mlx.ziepe.ca (174.3.196.123) by AM0PR05MB4450.eurprd05.prod.outlook.com (2603:10a6:208:5a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Wed, 4 Apr 2018 03:07:55 +0000 Received: from jgg by mlx.ziepe.ca with local (Exim 4.86_2) (envelope-from ) id 1f3Ylx-00018B-So; Tue, 03 Apr 2018 21:07:41 -0600 Date: Tue, 3 Apr 2018 21:07:41 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Leon Romanovsky , Sean Hefty , Roland Dreier Subject: [PATCH] RDMA/ucma: Check for a cm_id->device in all user calls that need it Message-ID: <20180404030741.GA32035@ziepe.ca> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [174.3.196.123] X-ClientProxiedBy: MWHPR1001CA0020.namprd10.prod.outlook.com (2603:10b6:301:2a::33) To AM0PR05MB4450.eurprd05.prod.outlook.com (2603:10a6:208:5a::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 476c0892-7e0d-44e7-f611-08d599d9431d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM0PR05MB4450; X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4450; 3:vNcwrNsjABeKAZ6LB9xmRjcnjEfgMqHiXi49XJoOuPJsgRpWGPZtbIRS9F+6UJuumIsCcjSauyN1CYdjyATRdjedDeepgPRUoKtFMT333HjcWGdVbjtT4NmbpG5mmi9USt0X4YPY+26F0OnTEGNevlUyVMVqDU4SpqTKT1h35mSutXu/niSGm68XjBVc7mMPu06rKanx70fl2IX9BUmKhEctE/lWt/Cow3zrD9So4P7wEp11YWgFsDNQOgLTFn7q; 25:y4vPIyipxoPu+qTbAazeubxxCOXRLeAFfSuKRIP8juPgbkxK6SALIU/JRxHZrmU5eLU75zahRWxscTrGZxgQgLUvta1hagANr2ize7aweLKtCjyQTRRLVCMYU7WYnNCmh9oAJzuDY5y31GAhGoelDpLcYVqijGGsOBcUe/U0XSVzOgat1TOScKcqEMr6n1c3PrRkbG7N7ziOqOUcUrpXsZxHlW+YuPRy3NSmRHnYKB/5rfy28nyNyq1ziqq6ajGjQRhInaBVrPM5X05sQ7eOdCFAYBcy2epcNfYwiStR8yPwkuaFhAJKpJ5WRpB/wytZhIaW4tIX1dx82kjGniHvKg==; 31:JKZZqz3fqC3QH1f//2MedwYhbITl7I88H/ruBGhFbYK7pV5SO7s+oTf227S6d56KAm5xv07vh7GBJ/5SNBxTQpMSjvrd75wFL86sQx3YJxMLg4eJj1zD4QxqETu7Gn5VNCOPLDFRvg18g6yBsfpayrWLXs+2CbAXw66oAYrXeoE0nhHSulLpTqFtgfz7RFZKnh6qvy/TjW4R7lReiaBzKHLyKBSQXZEHUg+otUPSOcY= X-MS-TrafficTypeDiagnostic: AM0PR05MB4450: X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4450; 20:wvZql0nSL+YJtN+DSB5Yno3V8UPBVphAkNZm0olIwir3jOYt6PkCe7FRIsOWjnYQBuWGiRc8niihTkUsGZCes78icAiibros1slvN+DZ/PcUBUuhYf7b0UtqV2dUjPUpuSDN1X0fqgMxnxrkXtSptm2GgIVN9ukpjXDp00BkF+A0C3XZMt+8C303km/1+P5h3kkKhsYE4wgLoAnrLS7U5e1tCvZ2oZtTW0srQFRv/w5w+Rd/mqYY0LsfwJjCLgenFBQ7bppZ8wHpt4qcN+AEoPyCl2E4FgA7SFIeWfw2GteSMQfKHce5L2+p8sPNJzhw38UeyynoWT/h+BVbO9u5TUydpDuLcvtC7FlLaIeEMDcm9Q8YXytq786h9Vc5W2rhu3NK4dMsZIAo7PiPOTZF0EXe1aebxBECSMP7AdNXiHtUaDkMZ1YvEyut7AcK4DRdtkodpJcBlDZRfARGuoV+3W4jHtzxHhm+V5x6oLbpLtr2N87Q5JIpAYOsf/14fYK0; 4:9WAT/XLvBOHjnOXZuVFx45JI8lStuNwywL5rBlHxOvFd+ToPNuv+Rt3A8FeVXPElBg4+r/nUNINqAt0/dx3Uynq/Oky9Eo3WroI3BGwr665nje83lPf72GFIgBlXrJ0BpHHunfnWf5uvsEgT6NeZFOIdGXgUyrgeJRcW+1RrsFGwyYZQ1WLIJXCjzcdWUDNoLybN1BoBUmY63KmdHhVSEoX0ah7+CUEA9p8xHx4AskyXBYiVCh13VaWfcHUlUN3LLgJ6sFex+0N24/vgWmQUcxteIVQnxW+R0h7M8o6jdXimDO5z+UjgpMOMb56oTx/8 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231221)(944501327)(52105095)(6055026)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:AM0PR05MB4450; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4450; X-Forefront-PRVS: 0632519F33 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(346002)(396003)(366004)(376002)(189003)(199004)(86362001)(122856001)(57986006)(7736002)(5660300001)(316002)(33896004)(47776003)(69596002)(54906003)(46656002)(58126008)(83796002)(386003)(81156014)(26005)(305945005)(486006)(476003)(105586002)(81166006)(9686003)(8936002)(8676002)(106356001)(52116002)(2906002)(478600001)(97736004)(36756003)(50466002)(68736007)(23726003)(9786002)(4326008)(6116002)(3846002)(9746002)(6916009)(33656002)(2361001)(16586007)(2351001)(66066001)(1076002)(53936002)(1857600001)(186003)(18370500001)(24400500001)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4450; H:mlx.ziepe.ca; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR05MB4450; 23:vL/KSwXiboDe5jpqj5bSiGUvRwu91nlmA47Gb0Rdu?= =?us-ascii?Q?6lo+QYgLP5wZSx9qsiA45ZNQnwKb4Wb0j0y1tmmSRjTRKC9y7zaNdbrokh8U?= =?us-ascii?Q?cFxdvuBaXrfk3jC+lCHNdAgPYYTgWIdroafWgypBWsT1tqPhJlOqoZNXmZwf?= =?us-ascii?Q?L00kqsLjkEwQu5MG384zFuEnabtNxAUpDJ26kvpRBljg4qET7XIKRNgVxBUR?= =?us-ascii?Q?r5dmXiluanKGsAVitC5ApGLk0Y7tvS5gwQItyuBjXxrsYG9iP+Vlv+l2EnnI?= =?us-ascii?Q?XXafpMy+7Gg++bSq8rM+eXyTmximbLCsP09lPUdpZLMFtysY7Gnh+Xh6qVN6?= =?us-ascii?Q?qOvKsmaODOM33QA0pC0uNTCVij6VXwkNHBsvyosBIopBo3EJhXTxW4XAVUoz?= =?us-ascii?Q?zecHammY7LJf1AyY0mFqAJPxCIOEASGMHlK9CoE6pCcoe5GBjwED+oLdbONh?= =?us-ascii?Q?NluYskBgX0iZt+11/TiAdyI/HGymjY0pzLS92Kz0yifc8R7+nr/ppss1jSku?= =?us-ascii?Q?V+WE/Geb4PzI7eTT8K/fwH8NLW+jHQrTqFUD7MLuThgL/I7CC7bx9YE/1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+tK15L6XRXpjEvI9UUeA5H12kZBp2BtSKMXFlY7UTpi/4e4fRXP7O6OKKS05O4waW9R6RMWbi7zlP3h2ngly1MSKO X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4450; 6:FtseCkhi4cfQFPWbcrZn+sxACC4knJU7AsRKDcd3KVb9rmHRPD0JUD370snh9haOedfQrTVEaPmc7oSvGyYke/wlkb5RYL5/8ltuClGZw1b7zzAstZv8gmnYiw/niOkR4kQnS1AG72Qo7vHutH/MvoP8B5yZkTm76ZSByV4evwMbBE1zXp0PLtyAlzwTCcK0+srh22axRumvHHSoPjlhEAJYbM+ksmJplZR6WTH+YsLzYBARU3zaI7cAwkbHrtMvJHTt2AJyAGb9WtvvOl2t/U2frHVKWBMOnLlR8PXQJTe/YurOzEpmY9Al3cxZKDzj2w2bLfFOjEAmnLyCb/dMV31hzUomsEqG9z6CPq+WT2iFD0oe26vYUx41FgS793cADQkWEK7u1Os2Vkb9p7j+nQmIoAdrt1vRGPQ7+h5GdE0wWLc6ZS4hJaRoUJMQv3dnT64EpHZpLx7iulQ4+nj28Q==; 5:fsz/8zMYwTLl1NzlevurIK94TWelkCQ9GoLTCQgpfP1uY9AwxqQAD/gXUjCaqw0JVqbur8hlRVayS3qrBDxX4m99I6K3nMEkFErvoU1DpNjpHL1wzu1mGdr4R89F14ZroRIYWz0V73LWP6EBxBB02nUACgvdQexpqxJNwr63rcg=; 24:UvcBOZVriIopjAzFaoNKQv0+exhx6Ql4d1D4ymCRXR1MMzzGxF/3qyVaS0JN7I1Hrr3dxrrazZocqnVNoXGTLDmCKQ20anc5kXOKs6+LgXo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4450; 7:YLcW4hgYA79in2aminGKJ7D/evpCb+q+mPHt32pqQ9QaMtOQqIcecwKXTKJ9P16r8pQLwF7df3TJMdnPzxjn3SOiWfZaAKpNm+E60DA8+rkpoAlGIFdZTVI2Vrttj3yiO6gtN97XB24/EnLJMlqwVwYfRrXt2XMl9/BLnM+u3mmBsxZMrQFgANePCE9Kd8w2EU06cpFdO+8/uWjNu6SPwX8SRhrKgMl3KDjwrpqSmD3cKrzdYW5JU+TkicnT4pph X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2018 03:07:55.3908 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 476c0892-7e0d-44e7-f611-08d599d9431d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4450 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is done by auditing all callers of ucma_get_ctx and switching the ones that unconditionally touch ->device to ucma_get_ctx_dev. This covers a little less than half of the call sites. The 11 remaining call sites to ucma_get_ctx() were manually audited. It looks like none of these cases cause bugs due to the FSM system inside the CMA, but documenting the requirement and the result of this audit is still productive. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/ucma.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) Inspired by Roland's patch, let us try hard to be sure we are done with this issue. diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index e74c82ee38a9f7..95e1eadae074ff 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -153,6 +153,21 @@ static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id) return ctx; } +/* + * Same as ucm_get_ctx but requires that ->cm_id->device is valid, eg that the + * CM_ID is bound. + */ +static struct ucma_context *ucma_get_ctx_dev(struct ucma_file *file, int id) +{ + struct ucma_context *ctx = ucma_get_ctx(file, id); + + if (IS_ERR(ctx)) + return ctx; + if (!ctx->cm_id->device) + return ERR_PTR(-EINVAL); + return ctx; +} + static void ucma_put_ctx(struct ucma_context *ctx) { if (atomic_dec_and_test(&ctx->ref)) @@ -734,7 +749,7 @@ static ssize_t ucma_resolve_route(struct ucma_file *file, if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; - ctx = ucma_get_ctx(file, cmd.id); + ctx = ucma_get_ctx_dev(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1050,7 +1065,7 @@ static ssize_t ucma_connect(struct ucma_file *file, const char __user *inbuf, if (!cmd.conn_param.valid) return -EINVAL; - ctx = ucma_get_ctx(file, cmd.id); + ctx = ucma_get_ctx_dev(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1092,7 +1107,7 @@ static ssize_t ucma_accept(struct ucma_file *file, const char __user *inbuf, if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; - ctx = ucma_get_ctx(file, cmd.id); + ctx = ucma_get_ctx_dev(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1120,7 +1135,7 @@ static ssize_t ucma_reject(struct ucma_file *file, const char __user *inbuf, if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; - ctx = ucma_get_ctx(file, cmd.id); + ctx = ucma_get_ctx_dev(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1139,7 +1154,7 @@ static ssize_t ucma_disconnect(struct ucma_file *file, const char __user *inbuf, if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; - ctx = ucma_get_ctx(file, cmd.id); + ctx = ucma_get_ctx_dev(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1167,15 +1182,10 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file, if (cmd.qp_state > IB_QPS_ERR) return -EINVAL; - ctx = ucma_get_ctx(file, cmd.id); + ctx = ucma_get_ctx_dev(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); - if (!ctx->cm_id->device) { - ret = -EINVAL; - goto out; - } - resp.qp_attr_mask = 0; memset(&qp_attr, 0, sizeof qp_attr); qp_attr.qp_state = cmd.qp_state; @@ -1381,7 +1391,7 @@ static ssize_t ucma_process_join(struct ucma_file *file, else return -EINVAL; - ctx = ucma_get_ctx(file, cmd->id); + ctx = ucma_get_ctx_dev(file, cmd->id); if (IS_ERR(ctx)) return PTR_ERR(ctx);