Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6117224pxv; Thu, 29 Jul 2021 06:59:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTk9O78XWdC8oAp/lk+6bKwyJao6tJ2W8BOPDTnyLuvsEnMlp7vm0u22f+W3ZeWTS5MfrF X-Received: by 2002:a92:4410:: with SMTP id r16mr3857203ila.82.1627567168667; Thu, 29 Jul 2021 06:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627567168; cv=none; d=google.com; s=arc-20160816; b=miAW1WPB9TREa0XqG5yHB7uRqKYbMTYnsgfJWAMOHo/G2psa99dvMnC3h+IiM3K0Xr VGEs+cq1oJhShLPF59O61Ncw2spnU5LhVTQJdKNaViLjwW08utiY6ZIjZ3L4rEhPX8z5 YNLkUOiU4bYAkq9FzZ48NXhxXA/iE7Bsr7P+rYSVHtrh5vmQUPrj1IHSAMtTzDmBR2z8 WP2lIucQeYnlkAngGZdCUQHXKmk+x+0LuoK5E5mMebrTtGGjDYOPtGIOR0Sgum1XtNzH QO5SCkEAgZGEdtT/N6+q49myyegWlQ/4MP2h/januUoEz56LVdzc7AN/r78sevg7OFwy uA9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ISksWs9MR5G6Vo7qRK6JK7hmp6NqH7sCABS+v69bLP4=; b=mHdy/C9zhAuuW8yzwIfrWqchovDctl2aVcdURE01XYNvEm7s8QoJyztJwA1DnJG1kc Ph+txBxQ71ToOzRXVGcP2LzZRVcQyn9dLrd3DLqZswJn6+qcFEtCnoqPbUQzM3dxG9e6 0wM3sRQmqyQWDCslOSjylaut9Yrsv8WhSfsmN7GdXvqIeiAihf1EcRqvx4L+10mYFdwx W1yXfcwce6UmzV9c9RgqUH2BiqiYaPK4aKXSqdcEgTlLZxmCYoP5Pga9YYp9/G4LF4R7 WMRG35oLFAsaMatfKURrPn3zlebtPOhOQE2zZ5nSTSSx1JHm/oStgQLcFLS7uI4tTz+H wI6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AUe8XvbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si3796739ilv.84.2021.07.29.06.59.16; Thu, 29 Jul 2021 06:59:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AUe8XvbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238051AbhG2N5H (ORCPT + 99 others); Thu, 29 Jul 2021 09:57:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238040AbhG2N45 (ORCPT ); Thu, 29 Jul 2021 09:56:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 73DB460F46; Thu, 29 Jul 2021 13:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627567014; bh=V5fhmUkEckptKwFyd126i7FzEo211+oEvFAECmJpPDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AUe8XvbZuT3f1Ahy/AbYsUH0yelWthNvdZKgVxbqlIxajeJSmc8c7NHvG3eNF857x L1z1aFh5Ba0EX6aKIObAFPtR3wyyd5fq2AdamJdCLfYeCLe6JwXFF1ZsCaj8F7strc FmdUU2/o5rb9v8DrD7wZqJayEs65ygrqT+cnvT7A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 09/17] net: annotate data race around sk_ll_usec Date: Thu, 29 Jul 2021 15:54:10 +0200 Message-Id: <20210729135137.557951320@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729135137.260993951@linuxfoundation.org> References: <20210729135137.260993951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 0dbffbb5335a1e3aa6855e4ee317e25e669dd302 ] sk_ll_usec is read locklessly from sk_can_busy_loop() while another thread can change its value in sock_setsockopt() This is correct but needs annotations. BUG: KCSAN: data-race in __skb_try_recv_datagram / sock_setsockopt write to 0xffff88814eb5f904 of 4 bytes by task 14011 on cpu 0: sock_setsockopt+0x1287/0x2090 net/core/sock.c:1175 __sys_setsockopt+0x14f/0x200 net/socket.c:2100 __do_sys_setsockopt net/socket.c:2115 [inline] __se_sys_setsockopt net/socket.c:2112 [inline] __x64_sys_setsockopt+0x62/0x70 net/socket.c:2112 do_syscall_64+0x4a/0x90 arch/x86/entry/common.c:47 entry_SYSCALL_64_after_hwframe+0x44/0xae read to 0xffff88814eb5f904 of 4 bytes by task 14001 on cpu 1: sk_can_busy_loop include/net/busy_poll.h:41 [inline] __skb_try_recv_datagram+0x14f/0x320 net/core/datagram.c:273 unix_dgram_recvmsg+0x14c/0x870 net/unix/af_unix.c:2101 unix_seqpacket_recvmsg+0x5a/0x70 net/unix/af_unix.c:2067 ____sys_recvmsg+0x15d/0x310 include/linux/uio.h:244 ___sys_recvmsg net/socket.c:2598 [inline] do_recvmmsg+0x35c/0x9f0 net/socket.c:2692 __sys_recvmmsg net/socket.c:2771 [inline] __do_sys_recvmmsg net/socket.c:2794 [inline] __se_sys_recvmmsg net/socket.c:2787 [inline] __x64_sys_recvmmsg+0xcf/0x150 net/socket.c:2787 do_syscall_64+0x4a/0x90 arch/x86/entry/common.c:47 entry_SYSCALL_64_after_hwframe+0x44/0xae value changed: 0x00000000 -> 0x00000101 Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 14001 Comm: syz-executor.3 Not tainted 5.13.0-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/busy_poll.h | 2 +- net/core/sock.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h index cf8f792743ec..c76a5e9894da 100644 --- a/include/net/busy_poll.h +++ b/include/net/busy_poll.h @@ -48,7 +48,7 @@ static inline bool net_busy_loop_on(void) static inline bool sk_can_busy_loop(const struct sock *sk) { - return sk->sk_ll_usec && !signal_pending(current); + return READ_ONCE(sk->sk_ll_usec) && !signal_pending(current); } bool sk_busy_loop_end(void *p, unsigned long start_time); diff --git a/net/core/sock.c b/net/core/sock.c index e6cbe137cb6f..956af38aa0d6 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -989,7 +989,7 @@ set_rcvbuf: if (val < 0) ret = -EINVAL; else - sk->sk_ll_usec = val; + WRITE_ONCE(sk->sk_ll_usec, val); } break; #endif -- 2.30.2