All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: kadlec@netfilter.org, fw@strlen.de,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	jiejiang@chromium.org, jasongustaman@chromium.org,
	garrick@chromium.org
Subject: Re: [PATCH v3] netfilter: conntrack: fix wrong ct->timeout value
Date: Wed, 19 Apr 2023 12:11:27 +0200	[thread overview]
Message-ID: <ZD++Tztor/BvG+ZY@calendula> (raw)
In-Reply-To: <ZD+a+R6+OgXm4QFZ@calendula>

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]

On Wed, Apr 19, 2023 at 09:40:44AM +0200, Pablo Neira Ayuso wrote:
> On Wed, Apr 19, 2023 at 01:15:26PM +0800, Tzung-Bi Shih wrote:
> > (struct nf_conn)->timeout is an interval before the conntrack
> > confirmed.  After confirmed, it becomes a timestamp[1].
> > 
> > It is observed that timeout of an unconfirmed conntrack:
> > - Set by calling ctnetlink_change_timeout().  As a result,
> >   `nfct_time_stamp` was wrongly added to `ct->timeout` twice[2].
> > - Get by calling ctnetlink_dump_timeout().  As a result,
> >   `nfct_time_stamp` was wrongly subtracted[3].
> > 
> > Separate the 2 cases in:
> > - Setting `ct->timeout` in __nf_ct_set_timeout().
> > - Getting `ct->timeout` in ctnetlink_dump_timeout().
> 
> Applied, thanks

I have to amend this patch, I have to collapsed the attached chunk.
Otherwise conntrack creation via ctnetlink breaks.


[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 834 bytes --]

diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index d3ee18854698..d65290646f63 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -2253,9 +2253,6 @@ ctnetlink_create_conntrack(struct net *net,
 	if (!cda[CTA_TIMEOUT])
 		goto err1;
 
-	timeout = (u64)ntohl(nla_get_be32(cda[CTA_TIMEOUT])) * HZ;
-	__nf_ct_set_timeout(ct, timeout);
-
 	rcu_read_lock();
  	if (cda[CTA_HELP]) {
 		char *helpname = NULL;
@@ -2319,6 +2316,9 @@ ctnetlink_create_conntrack(struct net *net,
 	/* we must add conntrack extensions before confirmation. */
 	ct->status |= IPS_CONFIRMED;
 
+	timeout = (u64)ntohl(nla_get_be32(cda[CTA_TIMEOUT])) * HZ;
+	__nf_ct_set_timeout(ct, timeout);
+
 	if (cda[CTA_STATUS]) {
 		err = ctnetlink_change_status(ct, cda);
 		if (err < 0)

      reply	other threads:[~2023-04-19 10:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19  5:15 [PATCH v3] netfilter: conntrack: fix wrong ct->timeout value Tzung-Bi Shih
2023-04-19  7:40 ` Pablo Neira Ayuso
2023-04-19 10:11   ` Pablo Neira Ayuso [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=ZD++Tztor/BvG+ZY@calendula \
    --to=pablo@netfilter.org \
    --cc=coreteam@netfilter.org \
    --cc=fw@strlen.de \
    --cc=garrick@chromium.org \
    --cc=jasongustaman@chromium.org \
    --cc=jiejiang@chromium.org \
    --cc=kadlec@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=tzungbi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.