Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2199010iof; Tue, 7 Jun 2022 22:59:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw55uLlWbLUwc76BXpvr3ZatUghye+aF3ARqhO4p2HkeiyrQeNlVVmMU3aSfV/jsBXKvwZI X-Received: by 2002:a17:902:cf0a:b0:156:39c9:4c44 with SMTP id i10-20020a170902cf0a00b0015639c94c44mr32546879plg.124.1654667990857; Tue, 07 Jun 2022 22:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667990; cv=none; d=google.com; s=arc-20160816; b=Xz6wSw1FpowSTnYeuVhX2I4UD14oXQO+8BNqhUlfB+cB+CFQXum1N6he3bBPQjYC8c DmJEY/F6mk+Tp77mQzBSPTZH4f6fYD/JMZpHGVOIMCnqoK3gDNefEEBi4KVFfIjWGRBO iRDQArssJS/sD/YhF9amDj2K3Orl8loA8H3TauEFb5Fx4wI3x+60roBVvnQVVG8fDm3B pIgvyeJo9ATZmB16LJbF+TO83cG0w0E3dIDVJFcXx/P+OIrrmTmvN8rjDxqphpQMSNoq lF3uZ0+w0vhpgvHcpXFZVtvv7zhkPjHhSbsDV0GPTbU8WrCpuNNPeXGlwbQqVvTaUFCS W79A== 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=YrLHCIBJzlUa2CanTCX6Y2ldrZ6uYkPiqlUAwL2ewbk=; b=t5VoJhNShH0edzSjLX1re32hMGJOatguq4z3ISHB07zbyooW4s+lS8w1lCgBxpoj5D Qcni0diofzSrnLuM3YomkwNfvZ+vNlmKMpjY4UtWhYkRdaiHplpmHrPHcyQQd+a7HWBO vLgFpeAWphxrrcS3wa4t1Or9hrcmJXUmZJofbbQ1hNVR2xSW16c5fTcGd8HfFbkv0JWQ WwMW/+phtRSegfKVEs5OVcFpTZ8YJneoKui6+tpXhzBZil21RoXJUVb+qU6JCaStS8uU HwMhm2/Q1Wr6Uwgc/xH8l6XUoYWxLKsJ107TyUVHI7DwBrDB7/KHmoko6Mx4JyeHeKQv GEyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KkFBaArb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o9-20020a170902778900b0015873958cc9si1698743pll.515.2022.06.07.22.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:59:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KkFBaArb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B06B745540B; Tue, 7 Jun 2022 22:26:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384272AbiFHAy7 (ORCPT + 99 others); Tue, 7 Jun 2022 20:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382692AbiFGVvo (ORCPT ); Tue, 7 Jun 2022 17:51:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C740C517FB; Tue, 7 Jun 2022 12:09:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2391261846; Tue, 7 Jun 2022 19:09:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37710C385A5; Tue, 7 Jun 2022 19:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628953; bh=1uQfHZyEVzAhNvhs2p8gXdX2bJGCq69ZMlYZfgFCGHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KkFBaArbMB23+ybXznT4Jf39LyjCOkXiO3/9NtRiPfsLS/kKdT92OScqv8yG9EX9T MFXFlPIfJdllyStg9pQ6Y/p1DAi6yiAS3k8Eh2yOySzQ08O9dobfXWY76uHJZWQ+Kh 2Smh2aTcYuJ7D9C8GC+7PmAZhhwHI7RLpwKgSghE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Dionne , David Howells , linux-afs@lists.infradead.org, "David S. Miller" , Sasha Levin Subject: [PATCH 5.18 517/879] rxrpc: Fix listen() setting the bar too high for the prealloc rings Date: Tue, 7 Jun 2022 19:00:35 +0200 Message-Id: <20220607165017.882093825@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ Upstream commit 88e22159750b0d55793302eeed8ee603f5c1a95c ] AF_RXRPC's listen() handler lets you set the backlog up to 32 (if you bump up the sysctl), but whilst the preallocation circular buffers have 32 slots in them, one of them has to be a dead slot because we're using CIRC_CNT(). This means that listen(rxrpc_sock, 32) will cause an oops when the socket is closed because rxrpc_service_prealloc_one() allocated one too many calls and rxrpc_discard_prealloc() won't then be able to get rid of them because it'll think the ring is empty. rxrpc_release_calls_on_socket() then tries to abort them, but oopses because call->peer isn't yet set. Fix this by setting the maximum backlog to RXRPC_BACKLOG_MAX - 1 to match the ring capacity. BUG: kernel NULL pointer dereference, address: 0000000000000086 ... RIP: 0010:rxrpc_send_abort_packet+0x73/0x240 [rxrpc] Call Trace: ? __wake_up_common_lock+0x7a/0x90 ? rxrpc_notify_socket+0x8e/0x140 [rxrpc] ? rxrpc_abort_call+0x4c/0x60 [rxrpc] rxrpc_release_calls_on_socket+0x107/0x1a0 [rxrpc] rxrpc_release+0xc9/0x1c0 [rxrpc] __sock_release+0x37/0xa0 sock_close+0x11/0x20 __fput+0x89/0x240 task_work_run+0x59/0x90 do_exit+0x319/0xaa0 Fixes: 00e907127e6f ("rxrpc: Preallocate peers, conns and calls for incoming service requests") Reported-by: Marc Dionne Signed-off-by: David Howells cc: linux-afs@lists.infradead.org Link: https://lists.infradead.org/pipermail/linux-afs/2022-March/005079.html Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rxrpc/sysctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/rxrpc/sysctl.c b/net/rxrpc/sysctl.c index 540351d6a5f4..555e0910786b 100644 --- a/net/rxrpc/sysctl.c +++ b/net/rxrpc/sysctl.c @@ -12,7 +12,7 @@ static struct ctl_table_header *rxrpc_sysctl_reg_table; static const unsigned int four = 4; -static const unsigned int thirtytwo = 32; +static const unsigned int max_backlog = RXRPC_BACKLOG_MAX - 1; static const unsigned int n_65535 = 65535; static const unsigned int n_max_acks = RXRPC_RXTX_BUFF_SIZE - 1; static const unsigned long one_jiffy = 1; @@ -89,7 +89,7 @@ static struct ctl_table rxrpc_sysctl_table[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = (void *)&four, - .extra2 = (void *)&thirtytwo, + .extra2 = (void *)&max_backlog, }, { .procname = "rx_window_size", -- 2.35.1