From: subashab@codeaurora.org
To: Florian Westphal <fw@strlen.de>, pablo@netfilter.org
Cc: Sean Tranchetti <stranche@codeaurora.org>,
netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf] x_tables: Properly close read section with read_seqcount_retry
Date: Mon, 16 Nov 2020 09:26:09 -0700 [thread overview]
Message-ID: <8256f40ba9b73181f121baafe12cac61@codeaurora.org> (raw)
In-Reply-To: <20201116141810.GB22792@breakpoint.cc>
>> We found that ip6t_do_table was reading stale values from the
>> READ_ONCE
>> leading to use after free when dereferencing per CPU jumpstack values.
>>
>> [https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/net/ipv6/netfilter/ip6_tables.c?h=v5.4.77#n282]
>> addend = xt_write_recseq_begin();
>> private = READ_ONCE(table->private); /* Address dependency. */
>>
>> We were able to confirm that the xt_replace_table & __do_replace
>> had already executed by logging the seqcount values. The value of
>> seqcount at ip6t_do_table was 1 more than the value at
>> xt_replace_table.
>
> Can you elaborate? Was that before xt_write_recseq_begin() or after?
The log in ip6t_do_table was after xt_write_recseq_begin().
[https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/net/ipv6/netfilter/ip6_tables.c?h=v5.4.77#n282]
addend = xt_write_recseq_begin();
The log in xt_replace_table was after raw_read_seqcount of
per_cpu(xt_recseq)
[https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/net/netfilter/x_tables.c?h=v5.4.77#n1400]
seqcount_t *s = &per_cpu(xt_recseq, cpu);
u32 seq = raw_read_seqcount(s);
In this specific run, we observed that the value in ip6t_do_table after
xt_write_recseq_begin() was 75316887. The value in xt_replace_table was
after
raw_read_seqcount of per_cpu(xt_recseq) was 75316886. This confirms that
the
private pointer assignment in xt_replace_table happened before the start
of
ip6t_do_table.
> You mean
> "private = READ_ONCE(table->private); /* Address dependency. */" in
> ip6_do_table did pick up the 'old' private pointer, AFTER xt_replace
> had updated it?
>
Yes, that is what we have observed from the logging.
>> diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
>> index 525f674..417ea1b 100644
>> --- a/net/netfilter/x_tables.c
>> +++ b/net/netfilter/x_tables.c
>> @@ -1431,11 +1431,11 @@ xt_replace_table(struct xt_table *table,
>> * Ensure contents of newinfo are visible before assigning to
>> * private.
>> */
>> - smp_wmb();
>> - table->private = newinfo;
>> + smp_mb();
>> + WRITE_ONCE(table->private, newinfo);
>
> The WRITE_ONCE looks correct.
>
>> /* make sure all cpus see new ->private value */
>> - smp_wmb();
>> + smp_mb();
>
> Is that to order wrt. seqcount_sequence?
Correct, we want to ensure that the table->private is updated and is
in sync on all CPUs beyond that point.
> Do you have a way to reproduce such crashes?
>
> I tried to no avail but I guess thats just because amd64 is more
> forgiving.
>
> Thanks!
Unfortunately we are seeing it on ARM64 regression systems which runs a
variety of
usecases so the exact steps are not known.
next prev parent reply other threads:[~2020-11-16 16:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-14 2:21 [PATCH nf] x_tables: Properly close read section with read_seqcount_retry Sean Tranchetti
2020-11-14 16:53 ` Florian Westphal
2020-11-16 6:32 ` subashab
2020-11-16 14:18 ` Florian Westphal
2020-11-16 16:26 ` subashab [this message]
2020-11-16 17:04 ` Florian Westphal
2020-11-16 17:51 ` subashab
2020-11-16 18:20 ` Florian Westphal
2020-11-18 12:13 ` Will Deacon
2020-11-18 12:42 ` Florian Westphal
2020-11-18 12:54 ` Will Deacon
2020-11-18 13:14 ` Florian Westphal
2020-11-18 20:39 ` subashab
2020-11-18 21:10 ` Florian Westphal
2020-11-20 5:53 ` subashab
2020-11-20 6:31 ` Florian Westphal
2020-11-20 9:44 ` Peter Zijlstra
2020-11-20 9:53 ` Peter Zijlstra
2020-11-20 10:20 ` Florian Westphal
2020-11-20 10:47 ` Peter Zijlstra
2020-11-21 1:27 ` subashab
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=8256f40ba9b73181f121baafe12cac61@codeaurora.org \
--to=subashab@codeaurora.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=stranche@codeaurora.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.