From: Ursula Braun <ubraun@linux.vnet.ibm.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [patch net-next] smc: some potential use after free bugs
Date: Fri, 27 Jan 2017 10:13:29 +0000 [thread overview]
Message-ID: <338b05ac-3bd0-0c8f-dee9-7dc9717cb9b7@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170126090527.GA966@mwanda>
On 01/26/2017 02:02 PM, walter harms wrote:
>
>
> Am 26.01.2017 12:23, schrieb Ursula Braun:
>>
>> On 01/26/2017 10:05 AM, Dan Carpenter wrote:
>>> Say we got really unlucky and these failed on the last iteration, then
>>> it could lead to a use after free bug.
>> thanks for reporting this! I had already a similar patch prepared, but not
>> yet submitted. It contains all your added lines plus these additional
>> pre-initializations at definition time:
>>
>> @@ -509,7 +509,7 @@ int smc_sndbuf_create(struct smc_sock *smc)
>> struct smc_connection *conn = &smc->conn;
>> struct smc_link_group *lgr = conn->lgr;
>> int tmp_bufsize, tmp_bufsize_short;
>> - struct smc_buf_desc *sndbuf_desc;
>> + struct smc_buf_desc *sndbuf_desc = NULL;
>> int rc;
>>
>> /* use socket send buffer size (w/o overhead) as start value */
>>
>> @@ -573,7 +575,7 @@ int smc_rmb_create(struct smc_sock *smc)
>> struct smc_connection *conn = &smc->conn;
>> struct smc_link_group *lgr = conn->lgr;
>> int tmp_bufsize, tmp_bufsize_short;
>> - struct smc_buf_desc *rmb_desc;
>> + struct smc_buf_desc *rmb_desc = NULL;
>> int rc;
>>
>> /* use socket recv buffer size (w/o overhead) as start value */
>>
>> If you do not contradict, I will post my enhanced patch version.
>
>
> Independend of that ...
>
> would it be possible to make sndbuf_desc->cpu_addr a zero size array
> and then simply do a:
> sndbuf_desc = kzalloc(sizeof(*sndbuf_desc)+tmp_bufsize, GFP_KERNEL);
>
The idea had been to keep DMA-mapping memory separate from other memory.
But I will experiment with your idea.
> (read also: is the whole list of __GPF* really needed ?)
Currently SMC-R tries to get large chunks of real consecutive memory
initially and lowers this requirement if not available.
We have future work in mind to implement a scattered solution, but
for now we accept initially failing memory allocations, and do not
want these sometimes likely failings to be noisy.
>
> that would make the memhandling more easy
>
> re,
> wh
>
>>>
>>> Fixes: cd6851f30386 ("smc: remote memory buffers (RMBs)")
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>
>>> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
>>> index 8b1d34378829..941279e1504e 100644
>>> --- a/net/smc/smc_core.c
>>> +++ b/net/smc/smc_core.c
>>> @@ -535,6 +535,7 @@ int smc_sndbuf_create(struct smc_sock *smc)
>>> /* if send buffer allocation has failed,
>>> * try a smaller one
>>> */
>>> + sndbuf_desc = NULL;
>>> continue;
>>> }
>>> rc = smc_ib_buf_map(lgr->lnk[SMC_SINGLE_LINK].smcibdev,
>>> @@ -543,6 +544,7 @@ int smc_sndbuf_create(struct smc_sock *smc)
>>> if (rc) {
>>> kfree(sndbuf_desc->cpu_addr);
>>> kfree(sndbuf_desc);
>>> + sndbuf_desc = NULL;
>>> continue; /* if mapping failed, try smaller one */
>>> }
>>> sndbuf_desc->used = 1;
>>> @@ -599,6 +601,7 @@ int smc_rmb_create(struct smc_sock *smc)
>>> /* if RMB allocation has failed,
>>> * try a smaller one
>>> */
>>> + rmb_desc = NULL;
>>> continue;
>>> }
>>> rc = smc_ib_buf_map(lgr->lnk[SMC_SINGLE_LINK].smcibdev,
>>> @@ -607,6 +610,7 @@ int smc_rmb_create(struct smc_sock *smc)
>>> if (rc) {
>>> kfree(rmb_desc->cpu_addr);
>>> kfree(rmb_desc);
>>> + rmb_desc = NULL;
>>> continue; /* if mapping failed, try smaller one */
>>> }
>>> rc = smc_ib_get_memory_region(lgr->lnk[SMC_SINGLE_LINK].roce_pd,
>>> @@ -619,6 +623,7 @@ int smc_rmb_create(struct smc_sock *smc)
>>> DMA_FROM_DEVICE);
>>> kfree(rmb_desc->cpu_addr);
>>> kfree(rmb_desc);
>>> + rmb_desc = NULL;
>>> continue;
>>> }
>>> rmb_desc->used = 1;
>>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
prev parent reply other threads:[~2017-01-27 10:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-26 9:05 [patch net-next] smc: some potential use after free bugs Dan Carpenter
2017-01-26 11:23 ` Ursula Braun
2017-01-26 11:32 ` Dan Carpenter
2017-01-26 13:02 ` walter harms
2017-01-27 10:13 ` Ursula Braun [this message]
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=338b05ac-3bd0-0c8f-dee9-7dc9717cb9b7@linux.vnet.ibm.com \
--to=ubraun@linux.vnet.ibm.com \
--cc=kernel-janitors@vger.kernel.org \
/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