Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp628638iog; Mon, 13 Jun 2022 09:27:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tx/Ah63gfB10uBpVmERAg/U+d/X09qMs7ngs5gM1SHlK2ccyUj0E7odmcVda6fu1EQ6H+d X-Received: by 2002:a17:90a:448c:b0:1ea:653c:282a with SMTP id t12-20020a17090a448c00b001ea653c282amr620636pjg.15.1655137626930; Mon, 13 Jun 2022 09:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137626; cv=none; d=google.com; s=arc-20160816; b=D20dbjwpnPbQmUYMUCRNNY4XrdWw7WqlSX3ZqfsU1gDzwoSbNdixveq5o9hWyskTju y0E8dO6bjUjm175FlxnlZMLurXHxa1Q7+ktDd5cGuCTsB9sUma7X56pjSp00epy1/x2A 9vU8app0INJeqgofr4R5YepHc/JX50NAFUaE0FJ7TVIn6FDsz3ZkA+/c2mavQ8zJPhfG eNS5F2tOkTyYPcgxIXZu+daPb95eJWXVAhEVql3NW7RFIKU6/X1ZEIuChbXbq2WEj9Fv IV2v7yqUFkBKLFoG5n6yoqhaZc3JB5V5dMnElsLfw9tS2eBYoDu5rZnQ1Q0RVBcRBTci ExDQ== 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=YB2i9CCFYHXEWiZtY0qwSQgjM7JavYrV6yvsx7u76SU=; b=Zmr8WTWPwmqEJD6qrWCdBOYAtsW0r2nyWZy6ZfVa3zw1Dwhqh9rNPK7pBB4S/XxC6D wnE2vaPfgClIWgEX1uyiZHWh51CbJJjB6CFrRgN+Ikku6nu3qyIKZioPRsKWMCZYAixg IyhNW37Q4bai72PvEasz6vgf0ofM/JrpHKnYOl18Ec52rYxxyCZfgKrmkoJ9Vzy3ERsB 0iEGhuP447tn+JVo0FePAhLhSyHnDtWXSb8z4kxbKeR5TjFT2a+U9i5Rtgz+DBnUf/XS 2ArEs74Lnnypy00JU7S1xC4ZJaz0TXUHWuV82P2Z9qCko2elKyvIOlQbt0iLTdHkdj6c Yp3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m+aDTERa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw18-20020a17090b4d1200b001e06828a394si45558pjb.27.2022.06.13.09.26.54; Mon, 13 Jun 2022 09:27:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m+aDTERa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S245610AbiFMKsL (ORCPT + 99 others); Mon, 13 Jun 2022 06:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348525AbiFMKoS (ORCPT ); Mon, 13 Jun 2022 06:44:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF7AC2AC79; Mon, 13 Jun 2022 03:25:24 -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 ams.source.kernel.org (Postfix) with ESMTPS id C36DBB80EA3; Mon, 13 Jun 2022 10:25:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BD9FC3411F; Mon, 13 Jun 2022 10:25:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115921; bh=A0HpK7TglfPM4Gwam1uPnihBLJAcsFvWh4WnQBaKaic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+aDTERaKuP1jqo2DAIzKgxx5gdgMLkc40iDD54HOHXzGJb0oqQ+WIhL1fJu9SwqA xtysfhoCL92m2YlkS3Iq+RgfMthfYYNo7tzIuFIv35OJLWlQT+/bGo4y5dp2cvCA7C GODt75rLvM0/lo0CripZxUh+lnVB1KL4txc75fKo= 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 4.14 079/218] rxrpc: Fix listen() setting the bar too high for the prealloc rings Date: Mon, 13 Jun 2022 12:08:57 +0200 Message-Id: <20220613094922.870596948@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 34c706d2f79c..f9afc21b7e2c 100644 --- a/net/rxrpc/sysctl.c +++ b/net/rxrpc/sysctl.c @@ -18,7 +18,7 @@ static struct ctl_table_header *rxrpc_sysctl_reg_table; static const unsigned int zero = 0; static const unsigned int one = 1; 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; @@ -114,7 +114,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