From patchwork Sun Aug 18 18:28:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 2846216 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A22169F271 for ; Sun, 18 Aug 2013 18:35:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F10D20214 for ; Sun, 18 Aug 2013 18:35:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AF7920201 for ; Sun, 18 Aug 2013 18:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754521Ab3HRSfg (ORCPT ); Sun, 18 Aug 2013 14:35:36 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:57181 "EHLO smtp1-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754427Ab3HRSfg (ORCPT ); Sun, 18 Aug 2013 14:35:36 -0400 Received: from localhost.localdomain (unknown [IPv6:2a01:e35:2e9f:6ac0:f909:bc73:7b7d:1daf]) by smtp1-g21.free.fr (Postfix) with ESMTP id B0793940128; Sun, 18 Aug 2013 20:35:27 +0200 (CEST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r7IITS5X031993; Sun, 18 Aug 2013 20:29:28 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id r7IITSHp031992; Sun, 18 Aug 2013 20:29:28 +0200 From: Yann Droneaud To: linux-rdma@vger.kernel.org Cc: Yann Droneaud Subject: [PATCH 08/22] ucm: check userspace input length Date: Sun, 18 Aug 2013 20:28:44 +0200 Message-Id: <254b9fcdfbee703e8f5fe33fc2e8b280018263c1.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 ucm functions check the length of the input buffer before reading the command content: this will detect truncated command and will prevent ucm 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/ucm.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c index b53e59b..7a35520 100644 --- a/drivers/infiniband/core/ucm.c +++ b/drivers/infiniband/core/ucm.c @@ -390,6 +390,9 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file, struct ib_ucm_event *uevent; int result = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(struct ib_ucm_event_resp)) return -ENOSPC; @@ -475,6 +478,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, struct ib_ucm_context *ctx; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -522,6 +528,9 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file, struct ib_ucm_context *ctx; int result = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -567,6 +576,9 @@ static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file, struct ib_ucm_context *ctx; int result = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -600,6 +612,9 @@ static ssize_t ib_ucm_init_qp_attr(struct ib_ucm_file *file, struct ib_qp_attr qp_attr; int result = 0; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (out_len < sizeof(resp)) return -ENOSPC; @@ -647,6 +662,9 @@ static ssize_t ib_ucm_listen(struct ib_ucm_file *file, struct ib_ucm_context *ctx; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -673,6 +691,9 @@ static ssize_t ib_ucm_notify(struct ib_ucm_file *file, struct ib_ucm_context *ctx; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -740,6 +761,9 @@ static ssize_t ib_ucm_send_req(struct ib_ucm_file *file, param.primary_path = NULL; param.alternate_path = NULL; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -800,6 +824,9 @@ static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file, param.private_data = NULL; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -842,6 +869,9 @@ static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file, const void *private_data = NULL; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -898,6 +928,9 @@ static ssize_t ib_ucm_send_info(struct ib_ucm_file *file, const void *info = NULL; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -950,6 +983,9 @@ static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file, const void *data = NULL; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -980,6 +1016,9 @@ static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file, const void *data = NULL; int result; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1019,6 +1058,9 @@ static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file, param.private_data = NULL; param.path = NULL; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; @@ -1062,6 +1104,9 @@ static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file, param.info = NULL; + if (in_len < sizeof(cmd)) + return -EINVAL; + if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT;