Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2296300ybl; Thu, 19 Dec 2019 11:10:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxRLOwFj8Hrp3igySiH6YHGz/yKlbrlNWoXsGKJvYWLB0JoGCZPuoKTbvlM01iLEpIF1q5a X-Received: by 2002:a05:6830:1cc9:: with SMTP id p9mr2922294otg.223.1576782608378; Thu, 19 Dec 2019 11:10:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782608; cv=none; d=google.com; s=arc-20160816; b=pNX9SvyjjtSZI9fUD8v1bkubJoeKFcCr6/WgkPe/w3Y9mbk8InTPf1KsJqKFrqFMDd 1CKMVe+sX59VNg93OoyyDx43dXGdcy2NFxjqAlokcLiILZQKZrvi+q4pK5OQztDfhIg8 LNpyl+SmbnAv/EEnT7mGWsWjQJdEMGFjYXhTuyC3D+pYuKrV0o4K+72KyQ6ihOz+XCV6 1sjcQBpIzn2we7I5cvHINAW1lgOD4JJQQnVvc7YiIaTBwVxlI5T4tLlAD1kKASnUOaAA qIWRwKdPcfXvD63B5WscQyoqC2NNiQ/bx+zLLsUEt3kyUaLXdLJU38gWwXzNXdPRoBQB hc4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PC9Bcp6gG00euQ5P4+1YDoMxiRqzmvMILcgHrkLtS4M=; b=kOSDvgW4VoZhYGKV19ERD2zERJiqna91yxpCaU+Kajnrkp08V7I5jH5txXP8BPb4tU XNTZnTUyxRikwKUCLrhfSPAsF/KQXctp3pKKYysEOm2HqY2qpnT0stLxp/NHUrul7GvD CuJl5IO5ALro6J40/gmZU3ABh5D+om+PnfZLPi+z9Of3UzRUCLiJwocgnU7Y075Yx34y ZlELbIWvlgCkUSmVmio9+r9tGleoMJKdO/L3MBPOZguZCFX1AVyv5p/YfLJGRFiwFSG8 qsl8B+ZGjw5shiWRBpYh+SIrcP/Hs7kLh+odpZGF8Fx0P0DM5e6VofFPmvt4JSHS1pXz GZKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PQEAk6K5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si3824388otk.86.2019.12.19.11.09.56; Thu, 19 Dec 2019 11:10:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PQEAk6K5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728484AbfLSSlK (ORCPT + 99 others); Thu, 19 Dec 2019 13:41:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:60076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727465AbfLSSlI (ORCPT ); Thu, 19 Dec 2019 13:41:08 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ACBA0222C2; Thu, 19 Dec 2019 18:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780868; bh=tCw8QJg3B9DlB75EFu+E5iiZzdj56AWbnDGLFoiTRXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQEAk6K55K/PEPpwGbdwTe2hWVr2J0QHtZLXbMEu1W1ysQCSz8rMnQpYNnoWBDmE9 VZ7G1fR7O26X5KVO/BbQ2U4z7BiQDsoy/pNJmoN+Gy5QxPiPFbcMgUdmMzHfgry6NW 8YdVGZYS+YM/ZwmGyzC2tuFARx1x2qyWCXmA+TEY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.4 149/162] tcp: Protect accesses to .ts_recent_stamp with {READ,WRITE}_ONCE() Date: Thu, 19 Dec 2019 19:34:17 +0100 Message-Id: <20191219183216.839942258@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guillaume Nault [ Upstream commit 721c8dafad26ccfa90ff659ee19755e3377b829d ] Syncookies borrow the ->rx_opt.ts_recent_stamp field to store the timestamp of the last synflood. Protect them with READ_ONCE() and WRITE_ONCE() since reads and writes aren't serialised. Use of .rx_opt.ts_recent_stamp for storing the synflood timestamp was introduced by a0f82f64e269 ("syncookies: remove last_synq_overflow from struct tcp_sock"). But unprotected accesses were already there when timestamp was stored in .last_synq_overflow. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Guillaume Nault Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/tcp.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -502,17 +502,17 @@ struct sock *cookie_v4_check(struct sock */ static inline void tcp_synq_overflow(const struct sock *sk) { - unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp; + unsigned long last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp); unsigned long now = jiffies; if (!time_between32(now, last_overflow, last_overflow + HZ)) - tcp_sk(sk)->rx_opt.ts_recent_stamp = now; + WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now); } /* syncookies: no recent synqueue overflow on this listening socket? */ static inline bool tcp_synq_no_recent_overflow(const struct sock *sk) { - unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp; + unsigned long last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp); /* If last_overflow <= jiffies <= last_overflow + TCP_SYNCOOKIE_VALID, * then we're under synflood. However, we have to use