Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc()

2 messages, 2 authors, 2021-02-23 · open the first message on its own page

Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc()

From: Gong, Sishuai <hidden>
Date: 2021-02-22 23:29:23

Hello,

We found a data race on dev->mtu between function __dev_set_mtu() and rawv6_send_hdrinc(). It happens with the following interleaving. 

writer: __dev_set_mtu()										reader: rawv6_send_hdrinc()
														if (length > rt->dst.dev->mtu) {
	WRITE_ONCE(dev->mtu, new_mtu);
															ipv6_local_error(sk, EMSGSIZE, fl6, rt->dst.dev->mtu);

If the writer happens to change dev->mtu to a value that is bigger than the variable ‘length’, then ipv6_local_error will read a value that doesn’t satisfy this conditional statement. While there is no need to use lock to protect the read, it is probably better to only read dev->mtu once in rawv6_send_hdrinc().


Thanks,
Sishuai

Re: Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc()

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: 2021-02-23 15:27:02

On Mon, Feb 22, 2021 at 6:30 PM Gong, Sishuai [off-list ref] wrote:
Hello,

We found a data race on dev->mtu between function __dev_set_mtu() and rawv6_send_hdrinc(). It happens with the following interleaving.

writer: __dev_set_mtu()                                                                         reader: rawv6_send_hdrinc()
                                                                                                                if (length > rt->dst.dev->mtu) {
        WRITE_ONCE(dev->mtu, new_mtu);
                                                                                                                        ipv6_local_error(sk, EMSGSIZE, fl6, rt->dst.dev->mtu);

If the writer happens to change dev->mtu to a value that is bigger than the variable ‘length’, then ipv6_local_error will read a value that doesn’t satisfy this conditional statement. While there is no need to use lock to protect the read, it is probably better to only read dev->mtu once in rawv6_send_hdrinc().
Makes sense. The same would then apply to raw_send_hdrinc().
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help