Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3928684imm; Mon, 8 Oct 2018 11:50:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV63hUZ3dezGE6cbQDqdx38fhiO3VZjHd9ohhbVH5TJqc/uQWhvJBfeSAUnMWmocAtHlCNIPw X-Received: by 2002:a17:902:6b46:: with SMTP id g6-v6mr24533177plt.19.1539024646660; Mon, 08 Oct 2018 11:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024646; cv=none; d=google.com; s=arc-20160816; b=qY1OuIDqgruZX9X97es2DZKksT2/sDFPsJ/vpWiIZkDrugdT1Orp6C4Uo+SDGgx7KL ipT+7i1ZNpWaRbBKqUdWapwJnfeKsBeX81RHixyTSN6sbniNa/MlbyU4fpf7OB/j2XkM UcpRgwoWKkLbxtlFvXhDATy/t92QajydArnw/Bg6i4yOWo5cmGonJUvtFSpTbTTICvmM 9L5kG4fGhN2wc2knn5wGLzcEUOuZWVaj9rtcLA/ea4pFZLgkLorhyzIoIaVEldwUbTLW YR5c71ss0PBNJ519QqGuIV6norgIA2sBxQm1VtOrUmgwYixWRm5HMHOg7q9Lqk8BHKoE Flug== 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=pISIXlU/YWqayPSMljqCIvRufqpy1lIIL0nIrC2fnU0=; b=0vbnTFwithA1cx/lGIHTPNzUEwSPzk1Tw4FYmuqa4fZhEfoTZpU+QKgYaeXXPZJDPO MVScDjJFaWLjXC6HxobI2hJHe90B17ucc6RTtfOl+IJ9It0LYumrVO4l2Ce4CCEXYy8c kR9Gq1TtLJzWq+G58Bi8m0qI4gKwSNXcrK6dCDs6Aqr04g00uywWp6QdSWbQL8l0SyAt zhFTct07xLrso0T7vE/ezo0MpetfqdzsSH1n7FY4oevhJEZW1QQimpwy3rZcXKwaTFZe Wg6otIrFz1cXTSGdcFSPZjgSiJ5R8rhjxAyN/i0+FTBML/JtVGl2zKUkiwgnRgp9+AM0 dCNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F+fJSxRc; 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 r28-v6si17608176pgb.444.2018.10.08.11.50.31; Mon, 08 Oct 2018 11:50:46 -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=F+fJSxRc; 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 S1732058AbeJICDZ (ORCPT + 99 others); Mon, 8 Oct 2018 22:03:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:52904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726391AbeJICDY (ORCPT ); Mon, 8 Oct 2018 22:03:24 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (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 31CDF21479; Mon, 8 Oct 2018 18:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024617; bh=7NwajtUdENz8Geo7aoCo5wZFr6PpVUEUa7qJl0cIxJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+fJSxRcGXZcC8G+uQeYkAlFslBwuivE+EP5RxwZt0KUUWI/SFLqDCwoV1pESMVtw 3m9QsD8QinnUdEI6mQgfM59ZWJSQxdCShAc4gqhfy6jMf4hAosXuk8G7NOXdsBId3x RGIrZtVKn7cIm367hYsfJWvGg4IIqt1S6xXEOEhg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.18 098/168] RDMA/ucma: check fd type in ucma_migrate_id() Date: Mon, 8 Oct 2018 20:31:18 +0200 Message-Id: <20181008175623.787059100@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn [ Upstream commit 0d23ba6034b9cf48b8918404367506da3e4b3ee5 ] The current code grabs the private_data of whatever file descriptor userspace has supplied and implicitly casts it to a `struct ucma_file *`, potentially causing a type confusion. This is probably fine in practice because the pointer is only used for comparisons, it is never actually dereferenced; and even in the comparisons, it is unlikely that a file from another filesystem would have a ->private_data pointer that happens to also be valid in this context. But ->private_data is not always guaranteed to be a valid pointer to an object owned by the file's filesystem; for example, some filesystems just cram numbers in there. Check the type of the supplied file descriptor to be safe, analogous to how other places in the kernel do it. Fixes: 88314e4dda1e ("RDMA/cma: add support for rdma_migrate_id()") Signed-off-by: Jann Horn Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/ucma.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -124,6 +124,8 @@ static DEFINE_MUTEX(mut); static DEFINE_IDR(ctx_idr); static DEFINE_IDR(multicast_idr); +static const struct file_operations ucma_fops; + static inline struct ucma_context *_ucma_find_context(int id, struct ucma_file *file) { @@ -1581,6 +1583,10 @@ static ssize_t ucma_migrate_id(struct uc f = fdget(cmd.fd); if (!f.file) return -ENOENT; + if (f.file->f_op != &ucma_fops) { + ret = -EINVAL; + goto file_put; + } /* Validate current fd and prevent destruction of id. */ ctx = ucma_get_ctx(f.file->private_data, cmd.id);