linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bob Pearson <rpearsonhpe@gmail.com>
To: Zhu Yanjun <zyjzyj2000@gmail.com>, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearson@hpe.com>
Subject: Re: [PATCH v3 11/17] rdma_rxe: Address an issue with hardened user copy
Date: Fri, 21 Aug 2020 23:16:59 -0500	[thread overview]
Message-ID: <f69f8a27-e4e6-88ae-77d8-358fde60d72e@gmail.com> (raw)
In-Reply-To: <4fd91289-7cd7-a62c-54ee-4ace9eb45a14@gmail.com>

On 8/21/20 10:32 PM, Zhu Yanjun wrote:
> On 8/21/2020 6:46 AM, Bob Pearson wrote:
>> Added a new feature to pools to let driver white list a region of
>> a pool object. This removes a kernel oops caused when create qp
>> returns the qp number so the next patch will work without errors.
>>
>> Signed-off-by: Bob Pearson <rpearson@hpe.com>
>> ---
>>   drivers/infiniband/sw/rxe/rxe_pool.c | 20 +++++++++++++++++---
>>   drivers/infiniband/sw/rxe/rxe_pool.h |  4 ++++
>>   2 files changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
>> index 5679714827ec..374e56689d30 100644
>> --- a/drivers/infiniband/sw/rxe/rxe_pool.c
>> +++ b/drivers/infiniband/sw/rxe/rxe_pool.c
>> @@ -40,9 +40,12 @@ struct rxe_type_info rxe_type_info[RXE_NUM_TYPES] = {
>>           .name        = "rxe-qp",
>>           .size        = sizeof(struct rxe_qp),
>>           .cleanup    = rxe_qp_cleanup,
>> -        .flags        = RXE_POOL_INDEX,
>> +        .flags        = RXE_POOL_INDEX
>> +                | RXE_POOL_WHITELIST,
>>           .min_index    = RXE_MIN_QP_INDEX,
>>           .max_index    = RXE_MAX_QP_INDEX,
>> +        .user_offset    = offsetof(struct rxe_qp, ibqp.qp_num),
>> +        .user_size    = sizeof(u32),
>>       },
>>       [RXE_TYPE_CQ] = {
>>           .name        = "rxe-cq",
>> @@ -116,10 +119,21 @@ int rxe_cache_init(void)
>>           type = &rxe_type_info[i];
>>           size = ALIGN(type->size, RXE_POOL_ALIGN);
>>           if (!(type->flags & RXE_POOL_NO_ALLOC)) {
>> -            type->cache =
>> -                kmem_cache_create(type->name, size,
>> +            if (type->flags & RXE_POOL_WHITELIST) {
>> +                type->cache =
>> +                    kmem_cache_create_usercopy(
>> +                        type->name, size,
>> +                        RXE_POOL_ALIGN,
>> +                        RXE_POOL_CACHE_FLAGS,
>> +                        type->user_offset,
>> +                        type->user_size, NULL);
>> +            } else {
>> +                type->cache =
>> +                    kmem_cache_create(type->name, size,
>>                             RXE_POOL_ALIGN,
>>                             RXE_POOL_CACHE_FLAGS, NULL);
>> +            }
>> +
>>               if (!type->cache) {
>>                   pr_err("Unable to init kmem cache for %s\n",
>>                          type->name);
>> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.h b/drivers/infiniband/sw/rxe/rxe_pool.h
>> index 664153bf9392..fc5b584a8137 100644
>> --- a/drivers/infiniband/sw/rxe/rxe_pool.h
>> +++ b/drivers/infiniband/sw/rxe/rxe_pool.h
>> @@ -17,6 +17,7 @@ enum rxe_pool_flags {
>>       RXE_POOL_INDEX        = BIT(1),
>>       RXE_POOL_KEY        = BIT(2),
>>       RXE_POOL_NO_ALLOC    = BIT(4),
>> +    RXE_POOL_WHITELIST    = BIT(5),
>>   };
>>     enum rxe_elem_type {
>> @@ -44,6 +45,9 @@ struct rxe_type_info {
>>       u32            min_index;
>>       size_t            key_offset;
>>       size_t            key_size;
>> +    /* for white listing where necessary */
> 
> s/where/when
> 
> 
>> +    unsigned int        user_offset;
>> +    unsigned int        user_size;
>>       struct kmem_cache    *cache;
>>   };
>>   
> 
> 
The reason for this change is that every time I do anything with rdma_rxe on current head of tree I get a kernel oops with a warning that there is a bad or missing white list. I traced this back to the user_copy routine which (recently) decided that when you copy just a part of a kernel memory object stored in a kmem cache that this represented a risk of leaking information from the kernel to user space. For the QP object the qp_num is copied back to user space in the user API. They also provided a new kmem_ccache_create_usercopy call that allows you to specify a 'whitelisted' portion of each object with an offset and length. So I just made it a feature of pools since it may come up again instead of treating QPs differently that all the other objects. This is part of a general program to harden the Linux kernel.
You can see the change to rxe_cache_init in the same file. Perhaps just dropping the comment would address the concern. See an earlier post I made with a pointer to an article in lwn describing the changes to the kernel.

  reply	other threads:[~2020-08-22  4:17 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-20 22:46 [PATCH v3 00/17] Memory window support for rdma_rxe Bob Pearson
2020-08-20 22:46 ` [PATCH v3 01/17] rdma_rxe: Added SPDX headers to rxe source files Bob Pearson
2020-08-24 10:03   ` Leon Romanovsky
2020-08-20 22:46 ` [PATCH v3 02/17] rdma_rxe: Fixed style warnings Bob Pearson
2020-08-27 12:52   ` Jason Gunthorpe
2020-08-20 22:46 ` [PATCH v3 03/17] ib_user_verbs.h: Added ib_uverbs_wc_opcode Bob Pearson
2020-08-27 12:53   ` Jason Gunthorpe
2020-08-20 22:46 ` [PATCH v3 04/17] ib_verbs.h: Added missing IB_WR_BIND_MW opcode Bob Pearson
2020-08-27 12:54   ` Jason Gunthorpe
2020-08-20 22:46 ` [PATCH v3 05/17] rdma_rxe: Added bind_mw parameters to rxe_send_wr Bob Pearson
2020-08-27 12:56   ` Jason Gunthorpe
2020-08-20 22:46 ` [PATCH v3 06/17] rdma_rxe: Added stubs for alloc_mw and dealloc_mw verbs Bob Pearson
2020-08-27 12:56   ` Jason Gunthorpe
2020-08-20 22:46 ` [PATCH v3 07/17] rdma_rxe: Separated MR and MW objects Bob Pearson
2020-08-20 22:46 ` [PATCH v3 08/17] rdma_rxe: Added mw object Bob Pearson
2020-08-22  3:39   ` Zhu Yanjun
2020-08-20 22:46 ` [PATCH v3 09/17] rdma_rxe: Extended pools to support both keys and indices Bob Pearson
2020-08-20 22:46 ` [PATCH v3 10/17] rdma_rxe: Implemented functional alloc_mw and dealloc_mw APIs Bob Pearson
2020-08-20 22:46 ` [PATCH v3 11/17] rdma_rxe: Address an issue with hardened user copy Bob Pearson
2020-08-22  3:32   ` Zhu Yanjun
2020-08-22  4:16     ` Bob Pearson [this message]
2020-08-24  8:47       ` Leon Romanovsky
2020-08-24  8:52       ` Leon Romanovsky
2020-08-24 23:52         ` Bob Pearson
2020-08-25  5:04           ` Leon Romanovsky
2020-08-20 22:46 ` [PATCH v3 12/17] rdma_rxe: Added bind mw API stub Bob Pearson
2020-08-20 22:46 ` [PATCH v3 13/17] rdma_rxe: Give MR and MW objects indices and keys Bob Pearson
2020-08-20 22:46 ` [PATCH v3 14/17] rdma_rxe: Added stub for invalidate mw Bob Pearson
2020-08-20 22:46 ` [PATCH v3 15/17] rdma_rxe: Added functional bind and invalidate MW ops Bob Pearson
2020-08-20 22:46 ` [PATCH v3 16/17] rdma_rxe: Implemented read/write/atomic access to MW Bob Pearson
2020-08-20 22:46 ` [PATCH v3 17/17] rdma_rxe: minor cleanups Bob Pearson
     [not found]   ` <a153a775-9b53-3ccc-4c2a-ec76f863d1a1@gmail.com>
2020-08-22  4:05     ` Bob Pearson
2020-08-24  9:02       ` Leon Romanovsky
2020-08-27 13:00   ` Jason Gunthorpe

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=f69f8a27-e4e6-88ae-77d8-358fde60d72e@gmail.com \
    --to=rpearsonhpe@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rpearson@hpe.com \
    --cc=zyjzyj2000@gmail.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;
as well as URLs for NNTP newsgroup(s).