Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Yann Droneaud <ydroneaud@opteya.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Steve Wise <swise@chelsio.com>, Roland Dreier <roland@kernel.org>,
	Sean Hefty <sean.hefty@intel.com>,
	Hal Rosenstock <hal.rosenstock@gmail.com>,
	linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org,
	netdev@vger.kernel.org, davem@davemloft.net,
	roland@purestorage.com, dm@chelsio.com, leedom@chelsio.com,
	santosh@chelsio.com, kumaras@chelsio.com, nirranjan@chelsio.com,
	hariprasad@chelsio.com, Steve Wise <swise@opengridcomputing.com>
Subject: Re: [patch] RDMA/cxgb4: info leak in c4iw_alloc_ucontext()
Date: Fri, 28 Mar 2014 11:27:48 +0100	[thread overview]
Message-ID: <1396002468.3297.63.camel@localhost.localdomain> (raw)
In-Reply-To: <20140328082428.GH25192@mwanda>

Hi,

Le vendredi 28 mars 2014 à 11:24 +0300, Dan Carpenter a écrit :
> The c4iw_alloc_ucontext_resp struct has a 4 byte hole after the last
> member and we should clear it before passing it to the user.
> 
> Fixes: 05eb23893c2c ('cxgb4/iw_cxgb4: Doorbell Drop Avoidance Bug Fixes')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 

It's not the proper fix for this issue: an explicit padding has to be
added (and initialized), see "Re: [PATCH net-next 2/2] cxgb4/iw_cxgb4:
Doorbell Drop Avoidance Bug Fixes"
http://marc.info/?i=1395848977.3297.15.camel@localhost.localdomain

In its current form, the c4iw_alloc_ucontext_resp structure does not
require padding on i386, so a 32bits userspace program using this
structure against a x86_64 kernel will make the kernel do a buffer
overflow in userspace, likely on stack, as answer of a GET_CONTEXT
request:

#include <infiniband/verbs.h>
#include <infiniband/kern-abi.h>

#define IBV_INIT_CMD_RESP(cmd, size, opcode, out, outsize) \
do {                                                       \
    (cmd)->command = IB_USER_VERBS_CMD_##opcode;           \
    (cmd)->in_words  = (size) / 4;                         \
    (cmd)->out_words = (outsize) / 4;                      \
    (cmd)->response  = (out);                              \
} while (0)

struct c4iw_alloc_ucontext_resp {
        struct ibv_get_context_resp ibv_resp;
        __u64 status_page_key;
        __u32 status_page_size;
};

struct ibv_context *alloc_context(struct ibv_device *ibdev,
                                  int cmd_fd)
{
    struct ibv_get_context cmd;
    struct c4iw_alloc_ucontext_resp resp;
    ssize_t sret;
    ...

    IBV_INIT_CMD_RESP(&cmd, sizeof(cmd),
                      GET_CONTEXT,
                      &resp, sizeof(resp));
    ...
    sret = write(context->cmd_fd,
                 &cmd,
                 sizeof(cmd));

    if (sret != sizeof(cmd)) {
        int err = errno;
        fprintf(stderr, "GET_CONTEXT failed: %d (%s)\n",
                err, strerror(err));
        ...
    }
    ...
}

Unfortunately, it's not the only structure which has this problem. I'm
currently preparing a report on this issue for this driver (cxgb4) and
another.

> diff --git a/drivers/infiniband/hw/cxgb4/provider.c b/drivers/infiniband/hw/cxgb4/provider.c
> index e36d2a2..a72aaa7 100644
> --- a/drivers/infiniband/hw/cxgb4/provider.c
> +++ b/drivers/infiniband/hw/cxgb4/provider.c
> @@ -107,7 +107,7 @@ static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
>  	struct c4iw_ucontext *context;
>  	struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
>  	static int warned;
> -	struct c4iw_alloc_ucontext_resp uresp;
> +	struct c4iw_alloc_ucontext_resp uresp = {};
>  	int ret = 0;
>  	struct c4iw_mm_entry *mm = NULL;
>  

Regards.

-- 
Yann Droneaud
OPTEYA

  reply	other threads:[~2014-03-28 10:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-14 16:22 [PATCH net-next 0/2] Doorbell drop Avoidance Bug fix for iw_cxgb4 Hariprasad Shenai
     [not found] ` <1394814128-8815-1-git-send-email-hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
2014-03-14 16:22   ` [PATCH net-next 1/2] cxgb4/iw_cxgb4: Treat CPL_ERR_KEEPALV_NEG_ADVICE as negative advice Hariprasad Shenai
2014-03-15  2:44   ` [PATCH net-next 0/2] Doorbell drop Avoidance Bug fix for iw_cxgb4 David Miller
2014-03-14 16:22 ` [PATCH net-next 2/2] cxgb4/iw_cxgb4: Doorbell Drop Avoidance Bug Fixes Hariprasad Shenai
     [not found]   ` <1394814128-8815-3-git-send-email-hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
2014-03-26 15:49     ` Yann Droneaud
     [not found]       ` <1395848977.3297.15.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-03-26 15:58         ` Steve Wise
2014-03-28  8:24       ` [patch] RDMA/cxgb4: info leak in c4iw_alloc_ucontext() Dan Carpenter
2014-03-28 10:27         ` Yann Droneaud [this message]
     [not found]           ` <1396002468.3297.63.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-03-28 10:58             ` David Laight
2014-05-02 23:56             ` Dan Carpenter
2014-05-04 21:21               ` [PATCH for v3.15 0/4] uverbs ABI fixes Yann Droneaud
2014-05-04 21:21                 ` [PATCH 2/4] RDMA/mlx5: add missing padding at end of struct mlx5_ib_create_srq Yann Droneaud
     [not found]                 ` <cover.1399216475.git.ydroneaud-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org>
2014-05-04 21:21                   ` [PATCH 1/4] RDMA/mlx5: add missing padding at end of struct mlx5_ib_create_cq Yann Droneaud
2014-05-04 21:21                   ` [PATCH 3/4] RDMA/cxgb4: add missing padding at end of struct c4iw_create_cq_resp Yann Droneaud
2014-05-04 21:21                   ` [PATCH 4/4] RDMA/cxgb4: add missing padding at end of struct c4iw_alloc_ucontext_resp Yann Droneaud
     [not found]                     ` <2236129ab4aa1ad1562858f363fb6fef0d6bc93b.1399216475.git.ydroneaud-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org>
2014-05-05 15:06                       ` Steve Wise
2014-05-05 16:59                         ` Yann Droneaud
     [not found]                           ` <1399309159.2957.19.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-05-05 17:01                             ` Steve Wise
2014-05-04 21:31                   ` [PATCH libcxgb4 0/2] uverbs ABI fixes Yann Droneaud
     [not found]                   ` <cover.1399235229.git.ydroneaud-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org>
2014-05-04 21:31                     ` [PATCH libcxgb4 1/2] kernel abi: adds explicit padding in struct c4iw_create_cq_resp Yann Droneaud
2014-05-04 21:31                     ` [PATCH libcxgb4 2/2] kernel abi: adds explicit padding in struct c4iw_alloc_ucontext_resp Yann Droneaud
2014-05-05 18:14                     ` [PATCH libcxgb4 0/2] uverbs ABI fixes Steve Wise
2014-05-04 21:41                   ` [PATCH libmlx5] abi: adds explicit padding on mlx5_create_cq and mlx5_create_srq Yann Droneaud
2014-05-05  9:01                   ` [PATCH for v3.15 0/4] uverbs ABI fixes Yann Droneaud
2014-05-04 21:46               ` [patch] RDMA/cxgb4: info leak in c4iw_alloc_ucontext() Yann Droneaud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1396002468.3297.63.camel@localhost.localdomain \
    --to=ydroneaud@opteya.com \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=dm@chelsio.com \
    --cc=hal.rosenstock@gmail.com \
    --cc=hariprasad@chelsio.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kumaras@chelsio.com \
    --cc=leedom@chelsio.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nirranjan@chelsio.com \
    --cc=roland@kernel.org \
    --cc=roland@purestorage.com \
    --cc=santosh@chelsio.com \
    --cc=sean.hefty@intel.com \
    --cc=swise@chelsio.com \
    --cc=swise@opengridcomputing.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox