All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Doug Ledford <dledford@redhat.com>
Cc: Boris Pismenny <borisp@mellanox.com>,
	stable@vger.kernel.org, security@kernel.org,
	Yevgeny Kliteynik <kliteyn@mellanox.com>,
	Tziporet Koren <tziporet@mellanox.com>,
	Alex Polak <alexpo@mellanox.com>
Subject: Re: [PATCH security IB/uverbs: Perform validity check for supplied port number in create_ah
Date: Thu, 29 Jun 2017 21:16:44 +0300	[thread overview]
Message-ID: <20170629181644.GD12009@mtr-leonro.local> (raw)
In-Reply-To: <1498754518.2929.1.camel@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3181 bytes --]

On Thu, Jun 29, 2017 at 12:41:58PM -0400, Doug Ledford wrote:
> On Tue, 2017-06-27 at 15:09 +0300, Leon Romanovsky wrote:
> >
> > Hi Doug and Security Team,
> >
> > How should we proceed with the following patch?
> >
> > The malicious user (non-root) can send ib_create_ah() comamnd
> > to exposed /sys/class/infiniband_verbs/uverbs* file.
>
> Your explanation is not making a lot of sense.  The
> /sys/class/infiniband_verbs/uverbs* files are directories, not files.
> Are you saying we have an open method by which you can open the
> directory in question and then send ib verbs commands over the
> directory file?  And even if you really mean some other file in that
> directory, why would we be fixing the create_ah handler instead of
> fixing the sysfs write handler for that file to not accept ib verbs
> commands?  Why would we be talking ib verbs commands on *any* sysfs
> file?

You are right,
It was my mistake and the real issue with /dev/infiniband/uverbs0, which
is open for everypne for write:

root@mtr-leonro:/sys/class/infiniband_verbs# ls -al /dev/infiniband/uverbs0
crw-rw-rw- 1 root root 231, 192 Jun 29 14:24 /dev/infiniband/uverbs0


>
> >  All that is
> > needed is to provide port number which is out-of-range and it will
> > kill the system.
>
> Why is this not an issue on the normal /dev/infiniband/uverbs* files
> (which are world writable)?  Is that merely because rdma-
> core/libibverbs checks the port number before submitting the command?
> If so, then a maliciously changed rdma-core/libibverbs would have the
> same problem.

It is exactly the problem. We started to run fuzzy testing on the
ibverbs interface with direct calls to uverbs files without any
libibverbs/rdma-core involvement. For years, we checked our stack as
a bundle (user + kernel), this is why libibvers/rdma-core limited us
to find it before.

>
> > There is need to be root to open uverbs* file, but after that those
> > persmissions can be dropped.
>
> I don't get the issue with the sysfs file, but the bug appears to be
> exploitable by any user who is willing to recompile rdma-core to bypass
> any checks it might have on input validity.

Please take my apology for sysfs. It was a mistake.

You don't need to create special library for that. Boris has
reproduction program, which does open/mmap/write in similar way to
rdma-core.


> From what I can tell, the
> offending code that should be the source of the problem is
> rdma_ah_find_type() which uses the user supplied port_num for an array
> lookup without checking it for validity, thereby being tricked into
> going outside the array bounds by user input.  We call
> rdma_ah_find_type() in two locations: ib_verbs.c:modify_qp() and
> ib_verbs.c:ib_uverbs_create_ah().  Why is this a bug in one and not the
> other?

We don't have fuzzy templates for all commands yet. IMHO, Boris has only
3-4 commands and didn't do modify_qp yet.

> And in modify_qp() it looks like we actually use cmd-
> >base.port_num, cmd->base.alt_port_num, and cmd->base.dest.port_num,
> all as user provided values without checking.

In general, I have 2 more similar bugs pending submissions and would
like to know the procedure.

Thanks

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2017-06-29 18:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 12:09 [PATCH security IB/uverbs: Perform validity check for supplied port number in create_ah Leon Romanovsky
2017-06-29 16:41 ` Doug Ledford
2017-06-29 18:16   ` Leon Romanovsky [this message]
2017-06-29 18:30     ` Linus Torvalds
2017-06-29 18:40       ` Leon Romanovsky

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=20170629181644.GD12009@mtr-leonro.local \
    --to=leon@kernel.org \
    --cc=alexpo@mellanox.com \
    --cc=borisp@mellanox.com \
    --cc=dledford@redhat.com \
    --cc=kliteyn@mellanox.com \
    --cc=security@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tziporet@mellanox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.