Netdev Archive on lore.kernel.org
 help / color / Atom feed
* Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc()
@ 2021-02-22 23:28 Gong, Sishuai
  2021-02-23 15:25 ` Willem de Bruijn
  0 siblings, 1 reply; 2+ messages in thread
From: Gong, Sishuai @ 2021-02-22 23:28 UTC (permalink / raw)
  To: davem, yoshfuji, dsahern; +Cc: netdev

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


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

* Re: Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc()
  2021-02-22 23:28 Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc() Gong, Sishuai
@ 2021-02-23 15:25 ` Willem de Bruijn
  0 siblings, 0 replies; 2+ messages in thread
From: Willem de Bruijn @ 2021-02-23 15:25 UTC (permalink / raw)
  To: Gong, Sishuai; +Cc: davem, yoshfuji, dsahern, netdev

On Mon, Feb 22, 2021 at 6:30 PM Gong, Sishuai <sishuai@purdue.edu> 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().

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 23:28 Data race on dev->mtu betwen __dev_set_mtu() and rawv6_send_hdrinc() Gong, Sishuai
2021-02-23 15:25 ` Willem de Bruijn

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git