public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2 nf] netfilter: seqadj: Fix one possible panic in seqadj when mem is exhausted
@ 2016-09-02  5:08 fgao
  2016-09-02  6:59 ` Florian Westphal
  0 siblings, 1 reply; 3+ messages in thread
From: fgao @ 2016-09-02  5:08 UTC (permalink / raw)
  To: pablo, netfilter-devel, coreteam, netdev; +Cc: gfree.wind, Gao Feng

From: Gao Feng <fgao@ikuai8.com>

When memory is exhausted, nfct_seqadj_ext_add may fail to add the seqadj
extension. But the function nf_ct_seqadj_init doesn't check if get valid
seqadj pointer by the nfct_seqadj, while other functions perform the
sanity check.

So the system would be panic when nfct_seqadj_ext_add failed.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 v2: Remove the unnessary seqadj check in nf_ct_seq_adjust
 v1: Inital patch

 net/netfilter/nf_conntrack_seqadj.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c
index dff0f0c..2c8e201 100644
--- a/net/netfilter/nf_conntrack_seqadj.c
+++ b/net/netfilter/nf_conntrack_seqadj.c
@@ -16,9 +16,14 @@ int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
 	if (off == 0)
 		return 0;
 
+	seqadj = nfct_seqadj(ct);
+	if (unlikely(!seqadj)) {
+		WARN_ONCE(1, "Missing nfct_seqadj_ext_add() setup call\n");
+		return 0;
+	}
+
 	set_bit(IPS_SEQ_ADJUST_BIT, &ct->status);
 
-	seqadj = nfct_seqadj(ct);
 	this_way = &seqadj->seq[dir];
 	this_way->offset_before	 = off;
 	this_way->offset_after	 = off;
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2 nf] netfilter: seqadj: Fix one possible panic in seqadj when mem is exhausted
  2016-09-02  5:08 [PATCH v2 1/2 nf] netfilter: seqadj: Fix one possible panic in seqadj when mem is exhausted fgao
@ 2016-09-02  6:59 ` Florian Westphal
  2016-09-02  7:07   ` Gao Feng
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2016-09-02  6:59 UTC (permalink / raw)
  To: fgao; +Cc: pablo, netfilter-devel, coreteam, netdev, gfree.wind

fgao@ikuai8.com <fgao@ikuai8.com> wrote:
> From: Gao Feng <fgao@ikuai8.com>
> 
> When memory is exhausted, nfct_seqadj_ext_add may fail to add the seqadj
> extension. But the function nf_ct_seqadj_init doesn't check if get valid
> seqadj pointer by the nfct_seqadj, while other functions perform the
> sanity check.
> 
> So the system would be panic when nfct_seqadj_ext_add failed.
> 
> Signed-off-by: Gao Feng <fgao@ikuai8.com>

> diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c
> index dff0f0c..2c8e201 100644
> --- a/net/netfilter/nf_conntrack_seqadj.c
> +++ b/net/netfilter/nf_conntrack_seqadj.c
> @@ -16,9 +16,14 @@ int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
>  	if (off == 0)
>  		return 0;
>  
> +	seqadj = nfct_seqadj(ct);
> +	if (unlikely(!seqadj)) {
> +		WARN_ONCE(1, "Missing nfct_seqadj_ext_add() setup call\n");
> +		return 0;
> +	}
> +

Not sure this WARN() is really needed, I would remove it (since its most
likely only missing due to memory shortage).

Other than that, this looks good.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2 nf] netfilter: seqadj: Fix one possible panic in seqadj when mem is exhausted
  2016-09-02  6:59 ` Florian Westphal
@ 2016-09-02  7:07   ` Gao Feng
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Feng @ 2016-09-02  7:07 UTC (permalink / raw)
  To: Florian Westphal
  Cc: Pablo Neira Ayuso, Netfilter Developer Mailing List, coreteam,
	Linux Kernel Network Developers

Hi Florian,

On Fri, Sep 2, 2016 at 2:59 PM, Florian Westphal <fw@strlen.de> wrote:
> fgao@ikuai8.com <fgao@ikuai8.com> wrote:
>> From: Gao Feng <fgao@ikuai8.com>
>>
>> When memory is exhausted, nfct_seqadj_ext_add may fail to add the seqadj
>> extension. But the function nf_ct_seqadj_init doesn't check if get valid
>> seqadj pointer by the nfct_seqadj, while other functions perform the
>> sanity check.
>>
>> So the system would be panic when nfct_seqadj_ext_add failed.
>>
>> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>
>> diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c
>> index dff0f0c..2c8e201 100644
>> --- a/net/netfilter/nf_conntrack_seqadj.c
>> +++ b/net/netfilter/nf_conntrack_seqadj.c
>> @@ -16,9 +16,14 @@ int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
>>       if (off == 0)
>>               return 0;
>>
>> +     seqadj = nfct_seqadj(ct);
>> +     if (unlikely(!seqadj)) {
>> +             WARN_ONCE(1, "Missing nfct_seqadj_ext_add() setup call\n");
>> +             return 0;
>> +     }
>> +
>
> Not sure this WARN() is really needed, I would remove it (since its most
> likely only missing due to memory shortage).
>
> Other than that, this looks good.
>

I prefer to keep the warning, although it only happens caused by mem
shortage now.
But it would give the accurate description, if the nfct_seqadj_ext_add
was lost when new features were depending on synadj.


Best Regards
Feng



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-02  7:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-02  5:08 [PATCH v2 1/2 nf] netfilter: seqadj: Fix one possible panic in seqadj when mem is exhausted fgao
2016-09-02  6:59 ` Florian Westphal
2016-09-02  7:07   ` Gao Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox