Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1272491pxb; Fri, 22 Jan 2021 11:08:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbTxFLIETZGc1+4oKPiNho9Rykwrn2VuUQR8CIrOFYBorOahPZZdYkLW8WBbfq5HlaLjus X-Received: by 2002:a50:fd12:: with SMTP id i18mr4416521eds.220.1611342501573; Fri, 22 Jan 2021 11:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611342501; cv=none; d=google.com; s=arc-20160816; b=TmG9JhXlPvv+zlodCGaK1gftoyrZOwkWjEUF+5Ljc0/m7ZPV9auCIryECskuCsHthS nUHyWryhiw985sWM/HJHkL2jPZHp+4OsSk78kvWSIwpCNf6p9FYi4xADPwonDf7/jcEt UV+xwHPUS6zv4SNiPb3magaLodwQmB3DHHyLIoWCo2PgWKzU9huGU8pUrhvTyQ+kff5b 3V63JGAPjtPAOretkiSUxneUAck4PT+FxW8DrwZQSfP0kkQNS6hPz+fcTVd8MuEP9IdX JfIA23gRfWSxpfzGjLi8p2Ib4TBsDqkmXCCBx39znKelaTYE+7imWiFRE3YZu864pR3S TtUw== 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=45N0V0147WTlnqo32Bh6tKCzVrbZC07bwX7l8l+d5J0=; b=vO5MqbSpKFz18PNyb0y1NJG2z+h9j9jwy0jbdMIZKhp16fMCVlRIoPwD4OIHbGTCuf xgjK1+N5yumr+RvSiHDBx3irRJ0j9wDjlRlJJxf58eDnC7IzrWkLtQaDEuwM7UIVw2o+ qbsa0hSDjjYX9/ygn+AYgrp/asBm8vh9SRsb92v5fr1i1AMN1gWmn6EAYf5B3GXeTshd sozwPEJMmIYnPz9s+wsfPoPi3rQ+ZPRGGCYPlMUb2uEEkB0cb+taA0o6Tvt2WrrzaApM m7/h5Z2mTMtJYyJdBNE0/UNesN7qJfTxdt6JnfAZf2PcnPBPCMkuKb9W2e5ahZwyCBbZ MevA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qCSZ5fqP; 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 mm24si2981007ejb.266.2021.01.22.11.07.56; Fri, 22 Jan 2021 11:08:21 -0800 (PST) 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=qCSZ5fqP; 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 S1730026AbhAVTGs (ORCPT + 99 others); Fri, 22 Jan 2021 14:06:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:39306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728562AbhAVOWy (ORCPT ); Fri, 22 Jan 2021 09:22:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E7AC223A60; Fri, 22 Jan 2021 14:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611325000; bh=c7307HwfZwAlMqt+hiYWQXTs3XtiaUMUi6OPK9QaNpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qCSZ5fqPZlb3LphmZWzQd2aXYBn6fDzr/fzMwKxV2cWVhFnp6wd7npd+2lAcji0rW dNXJEDXUWHNe7TKaKLWa36Ds1XxIFBe2XJ8G4EWxBLzaBihzeyxGwFxHoo3L3f18wk UGqwIrJIq09Bal1DJox3vgkB83PpQez9hIZjP3ms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Baptiste Lepers , Willem de Bruijn , Jakub Kicinski Subject: [PATCH 5.4 12/33] udp: Prevent reuseport_select_sock from reading uninitialized socks Date: Fri, 22 Jan 2021 15:12:28 +0100 Message-Id: <20210122135734.077786558@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122135733.565501039@linuxfoundation.org> References: <20210122135733.565501039@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: Baptiste Lepers [ Upstream commit fd2ddef043592e7de80af53f47fa46fd3573086e ] reuse->socks[] is modified concurrently by reuseport_add_sock. To prevent reading values that have not been fully initialized, only read the array up until the last known safe index instead of incorrectly re-reading the last index of the array. Fixes: acdcecc61285f ("udp: correct reuseport selection with connected sockets") Signed-off-by: Baptiste Lepers Acked-by: Willem de Bruijn Link: https://lore.kernel.org/r/20210107051110.12247-1-baptiste.lepers@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/sock_reuseport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/core/sock_reuseport.c +++ b/net/core/sock_reuseport.c @@ -302,7 +302,7 @@ select_by_hash: i = j = reciprocal_scale(hash, socks); while (reuse->socks[i]->sk_state == TCP_ESTABLISHED) { i++; - if (i >= reuse->num_socks) + if (i >= socks) i = 0; if (i == j) goto out;