Subject: Re: [PATCH net-next] xfrm: check function pointer of xfrm_mgr before use it

From: Sergei Shtylyov <[email-masked]>
Date: Sun, 10 Nov 2013 23:03:19 +0400

Hello.

On 10-11-2013 18:25, [email-masked] wrote:

> From: "baker.zhang" <[email-masked]>

> Signed-off-by: baker.zhang <[email-masked]>
> ---
> For current kernel source, there is no problem.

> In our vpn product, we need a xfrm_km in kernel module
> to monitor the xfrm state change.
> thus, the 'acquire' and 'compile_policy' may be NULL.

> So I think we should do the check before use it.

>   net/xfrm/xfrm_state.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)

> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index b9c3f9e..541f684 100644
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c
[...]
> @@ -1783,10 +1785,12 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
>   	err = -EINVAL;
>   	rcu_read_lock();
>   	list_for_each_entry_rcu(km, &xfrm_km_list, list) {
> -		pol = km->compile_policy(sk, optname, data,
> -					 optlen, &err);
> -		if (err >= 0)
> -			break;
> +		if (km->compile_policy) {
> +			pol = km->compile_policy(sk, optname, data,
> +					optlen, &err);

    According the networking coding style, the continuation line should start 
right under 'sk' on the previous line.

WBR, Sergei