From patchwork Sun Aug 18 18:28:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 2846218 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2BF28BF546 for ; Sun, 18 Aug 2013 18:35:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 990C720212 for ; Sun, 18 Aug 2013 18:35:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 86BC520201 for ; Sun, 18 Aug 2013 18:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754548Ab3HRSft (ORCPT ); Sun, 18 Aug 2013 14:35:49 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:57753 "EHLO smtp1-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754427Ab3HRSfs (ORCPT ); Sun, 18 Aug 2013 14:35:48 -0400 Received: from localhost.localdomain (unknown [IPv6:2a01:e35:2e9f:6ac0:f909:bc73:7b7d:1daf]) by smtp1-g21.free.fr (Postfix) with ESMTP id D73A194019F; Sun, 18 Aug 2013 20:35:39 +0200 (CEST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r7IITTZI032009; Sun, 18 Aug 2013 20:29:29 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id r7IITT8O032008; Sun, 18 Aug 2013 20:29:29 +0200 From: Yann Droneaud To: linux-rdma@vger.kernel.org Cc: Yann Droneaud Subject: [PATCH 12/22] ucma: check userspace input length Date: Sun, 18 Aug 2013 20:28:48 +0200 Message-Id: <609d01c8b8d1b5fd121222b5fda4072f18239130.1376847403.git.ydroneaud@opteya.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Makes ucma functions check the length of the input buffer before reading the command content: this will detect truncated command and will prevent ucma from reading past userspace provided buffer. Signed-off-by: Yann Droneaud Link: http://mid.gmane.org/cover.1376847403.git.ydroneaud@opteya.com --- drivers/infiniband/core/ucma.c | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index b0f189b..9e9e899 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -297,6 +297,9 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf, struct ucma_event *uevent; int ret = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof uevent->resp) return -ENOSPC; @@ -374,6 +377,9 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf, enum ib_qp_type qp_type; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -486,6 +492,9 @@ static ssize_t ucma_destroy_id(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -519,6 +528,9 @@ static ssize_t ucma_bind_ip(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -539,6 +551,9 @@ static ssize_t ucma_bind(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -563,6 +578,9 @@ static ssize_t ucma_resolve_ip(struct ucma_file *file, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -586,6 +604,9 @@ static ssize_t ucma_resolve_addr(struct ucma_file *file, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -612,6 +633,9 @@ static ssize_t ucma_resolve_route(struct ucma_file *file, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -708,6 +732,9 @@ static ssize_t ucma_query_route(struct ucma_file *file, struct sockaddr *addr; int ret = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -889,6 +916,9 @@ static ssize_t ucma_query(struct ucma_file *file, void __user *response; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -940,6 +970,9 @@ static ssize_t ucma_connect(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -963,6 +996,9 @@ static ssize_t ucma_listen(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -985,6 +1021,9 @@ static ssize_t ucma_accept(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1013,6 +1052,9 @@ static ssize_t ucma_reject(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1032,6 +1074,9 @@ static ssize_t ucma_disconnect(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1054,6 +1099,9 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file, struct ib_qp_attr qp_attr; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -1187,6 +1235,9 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf, void *optval; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1217,6 +1268,9 @@ static ssize_t ucma_notify(struct ucma_file *file, const char __user *inbuf, struct ucma_context *ctx; int ret; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1295,6 +1349,9 @@ static ssize_t ucma_join_ip_multicast(struct ucma_file *file, struct rdma_ucm_join_ip_mcast cmd; struct rdma_ucm_join_mcast join_cmd; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1314,6 +1371,9 @@ static ssize_t ucma_join_multicast(struct ucma_file *file, { struct rdma_ucm_join_mcast cmd; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1329,6 +1389,9 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file, struct ucma_multicast *mc; int ret = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -1412,6 +1475,9 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file, struct ucma_file *cur_file; int ret = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT;