From: Fan Du <fan.du@windriver.com>
To: Paul Moore <paul@paul-moore.com>
Cc: <steffen.klassert@secunet.com>, <davem@davemloft.net>,
<netdev@vger.kernel.org>
Subject: Re: [PATCH net-next] {selinux, af_key} Rework pfkey_sadb2xfrm_user_sec_ctx
Date: Thu, 17 Oct 2013 09:34:53 +0800 [thread overview]
Message-ID: <525F3EBD.80406@windriver.com> (raw)
In-Reply-To: <1541456.gnvYckRYYL@sifl>
On 2013年10月16日 23:15, Paul Moore wrote:
> On Wednesday, October 16, 2013 02:15:14 PM Fan Du wrote:
>> Taking advantages of sadb_x_sec_ctx and xfrm_user_sec_ctx share the same
>> structure arrangement, rework pfkey_sadb2xfrm_user_sec_ctx by casting
>> sadb_x_sec_ctx into xfrm_user_sec_ctx with minor len fix.
>>
>> Then we can:
>> -Avoid kmalloc/free memory for xfrm_user_sec_ctx, sadb_x_sec_ctx would be
>> fine.
>> -Fix missing return value check bug for pfkey_compile_policy when
>> kmalloc fails
>>
>> Signed-off-by: Fan Du<fan.du@windriver.com>
>> ---
>> net/key/af_key.c | 33 +--------------------------------
>> 1 file changed, 1 insertion(+), 32 deletions(-)
>>
>> diff --git a/net/key/af_key.c b/net/key/af_key.c
>> index 9d58537..c7d304d 100644
>> --- a/net/key/af_key.c
>> +++ b/net/key/af_key.c
>> @@ -435,22 +435,9 @@ static inline int verify_sec_ctx_len(const void *p)
>>
>> static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(const
>> struct sadb_x_sec_ctx *sec_ctx) {
>> - struct xfrm_user_sec_ctx *uctx = NULL;
>> - int ctx_size = sec_ctx->sadb_x_ctx_len;
>> -
>> - uctx = kmalloc((sizeof(*uctx)+ctx_size), GFP_KERNEL);
>> -
>> - if (!uctx)
>> - return NULL;
>> + struct xfrm_user_sec_ctx *uctx = (struct xfrm_user_sec_ctx *)sec_ctx;
>>
>> uctx->len = pfkey_sec_ctx_len(sec_ctx);
>> - uctx->exttype = sec_ctx->sadb_x_sec_exttype;
>> - uctx->ctx_doi = sec_ctx->sadb_x_ctx_doi;
>> - uctx->ctx_alg = sec_ctx->sadb_x_ctx_alg;
>> - uctx->ctx_len = sec_ctx->sadb_x_ctx_len;
>> - memcpy(uctx + 1, sec_ctx + 1,
>> - uctx->ctx_len);
>> -
>> return uctx;
>> }
>
> The fact that you are now changing sadb_x_sec_ctx->sadb_x_sec_len whenever
> pfkey_sadb2xfrm_user_sec_ctx() is called raises an eyebrow. Can you elaborate
> on why this is not a problem?
>
Thanks for your attention, Paul.
sadb_x_sec_ctx is extra headers passed down from user space, the usage of
of this data structure falls down to one of pfkey_funcs function only for
one time, more specifically speaking, it's only used by SELINUX for security
checking for each operation. In other words, sadb_x_sec_ctx involves with a
one shot business here. So the original codes seems do a lots of extra job
which could easily be avoid using casting operation.
--
浮沉随浪只记今朝笑
--fan
next prev parent reply other threads:[~2013-10-17 1:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-16 6:15 [PATCH net-next] {selinux, af_key} Rework pfkey_sadb2xfrm_user_sec_ctx Fan Du
2013-10-16 15:15 ` Paul Moore
2013-10-17 1:34 ` Fan Du [this message]
2013-10-17 9:51 ` Steffen Klassert
2013-10-18 1:18 ` Paul Moore
2013-10-18 19:58 ` David Miller
2013-10-21 3:01 ` Fan Du
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=525F3EBD.80406@windriver.com \
--to=fan.du@windriver.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=steffen.klassert@secunet.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).