From: Wei Yongjun <yjwei@cn•fujitsu.com>
To: Steffen Klassert <steffen.klassert@secunet•com>
Cc: David Miller <davem@davemloft•net>, netdev@vger•kernel.org
Subject: Re: xfrm: Fix initialize repl field of struct xfrm_state
Date: Tue, 22 Mar 2011 09:04:38 +0800 [thread overview]
Message-ID: <4D87F5A6.90704@cn.fujitsu.com> (raw)
In-Reply-To: <20110321120635.GA1290@secunet.com>
> On Mon, Mar 21, 2011 at 05:18:18PM +0800, Wei Yongjun wrote:
>>>> Btw, looking a bit closer to this. I think it would look a bit cleaner
>>>> if we would add the xfrm_init_replay() call to xfrm_init_state() and
>>>> to move the xfrm_init_state() call in xfrm_state_construct() behind
>>>> the assign of the replay settings.
>>> The xfrm_init_replay() should be call after the call to
>>> xfrm_update_ae_params(x, attrs);
>>> since xfrm_update_ae_params() may update the replay_esn.
>>>
>>> So we need move the xfrm_init_state() call just before return x.
>>
>> Oh, sorry, the memcpy looks like dup code since we used
>> kmemdup. It is the same attr XFRMA_REPLAY_ESN_VAL.
>>
> Indeed, we don't need the memcpy here because we do a kmemdup when we
> allocate repay_esn/preplay_esn. But we need to memcpy if we call
> xfrm_update_ae_params() from xfrm_new_ae().
>
> So we could just replace the kmemdup by kmalloc when we allocate
> repay_esn/preplay_esn and move xfrm_init_state() at the end of the
> function, as you suggested. xfrm_update_ae_params() would initialize
> x->replay_esn and x->preplay_esn properly then.
BTW, looking into more about this, another path, XFRM_MSG_NEWAE,
can overwrite the x->replay_esn with the nla_data length, which
may larger then the size we malloc.
>>> The other issue:
>>> static void xfrm_update_ae_params()
>>> {
>>> ...
>>> memcpy(x->replay_esn, replay_esn,
>>> xfrm_replay_state_esn_len(replay_esn));
>>> ...
>>> }
>>>
>>> the memcpy() may cause memory overlap if we build a special
>>> nl_data, we should free it and then do kmemdup()?
>>>
next prev parent reply other threads:[~2011-03-22 1:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-21 5:45 xfrm: Fix initialize repl field of struct xfrm_state Wei Yongjun
2011-03-21 5:48 ` [PATCH] " Wei Yongjun
2011-03-21 5:55 ` David Miller
2011-03-21 6:36 ` Wei Yongjun
2011-03-21 6:46 ` David Miller
2011-03-21 6:49 ` Wei Yongjun
2011-03-21 7:54 ` Steffen Klassert
2011-03-21 7:44 ` [PATCH v2] " Wei Yongjun
2011-03-21 8:00 ` David Miller
2011-03-21 8:01 ` David Miller
2011-03-21 8:37 ` [PATCH v3] " Wei Yongjun
2011-03-22 1:08 ` David Miller
2011-03-21 8:25 ` Steffen Klassert
2011-03-21 9:10 ` Wei Yongjun
2011-03-21 9:18 ` Wei Yongjun
2011-03-21 12:06 ` Steffen Klassert
2011-03-22 1:04 ` Wei Yongjun [this message]
2011-03-22 13:14 ` Steffen Klassert
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=4D87F5A6.90704@cn.fujitsu.com \
--to=yjwei@cn$(echo .)fujitsu.com \
--cc=davem@davemloft$(echo .)net \
--cc=netdev@vger$(echo .)kernel.org \
--cc=steffen.klassert@secunet$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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