Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1415040pxy; Sat, 1 May 2021 12:58:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6bmDZ2qW2aQl77Wq1cvSfMY3HNhqhFXrlQlmXbCyz3zGCGDaPAKqVBv2RFRbGmROL84Y7 X-Received: by 2002:a17:906:eced:: with SMTP id qt13mr9871461ejb.382.1619899092805; Sat, 01 May 2021 12:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619899092; cv=none; d=google.com; s=arc-20160816; b=ZVtV+eDjelOQJP/XE60eZlAShaY7ISSNDG3Cbd5neeoP//qCz4JotQUiPtrnVDfJyj F4FPDQHv27JyhXgiqYat//ZszEGIJn+oPnZfxe9Y8Maroj6Q8rd5klbLQJeoPeYAIele C2BAskohBNF4EUbC2wAO//2mtC7D3wx+GcSsaDkW8SYmUU3hTk5kgPtpmH4f9AwvRzgY rIp+mdixkGqxUFJZCnHLOUOX9U5fuacz2416enLDDX5u6IQbumvxYn6Jj2n2kY7RWvfR 2j4AGQDOHKlZ/fWwHiQnFfxbC/5HQLKdawzXEOFVBHssIQb64P1qxa+1yHUgTVSz93ks FFkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=84/L42HJMcSoYItRnnRdLZZPAznzFAB6aWPype0QEzQ=; b=qpsj+DMI2cted/4qEG3vj5mg4ulYluA9irU4wh7hAeTDZeFSL3lAo8ul5Mxmf4LyuF S03piMpP1AIj6+o8LfFKYBZgZ5cnJSQPrN4JO3R/mINUyp9AEYw9/uSwSkjncGKPK4vL wW+lKqGYFwTrvMDP2/H46g8np/+Rx01v6zY1vCtIFo3BOL64XpRwZyl5QTx22mth37+D xocktIgClt2Ti4GK/2EIDOWnOIzeSO1O8c25dp/bqPHvUCJ3sMGjivggoVKcLK9SL8Or 9tpvsr07xj/vWq9bocjAezu3yc7OJLvx6ZmhAHMT+GM24T4T6iaBv5TStk7Z/tbjJWTb 8KaA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si6210855ejw.376.2021.05.01.12.57.26; Sat, 01 May 2021 12:58:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231770AbhEATxM (ORCPT + 99 others); Sat, 1 May 2021 15:53:12 -0400 Received: from bmailout2.hostsharing.net ([83.223.78.240]:39245 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbhEATxL (ORCPT ); Sat, 1 May 2021 15:53:11 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1" (verified OK)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 9B61F2800B3D0; Sat, 1 May 2021 21:51:35 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 8EE261BC5; Sat, 1 May 2021 21:51:35 +0200 (CEST) Date: Sat, 1 May 2021 21:51:35 +0200 From: Lukas Wunner To: Mark Brown Cc: Joe Burmeister , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, nsaenz@kernel.org, phil@raspberrypi.com Subject: Re: [PATCH] spi: bcm2835: Fix buffer overflow with CS able to go beyond limit. Message-ID: <20210501195135.GA18501@wunner.de> References: <20210420083402.6950-1-joe.burmeister@devtank.co.uk> <7c9f9376-1a80-b624-7b9e-0f6d04437c02@devtank.co.uk> <271ad212-a606-620e-3f0c-d6bff272be3c@gmail.com> <380624c4-82f3-0e6e-8cdb-8a9732636db8@devtank.co.uk> <20210423115724.GB5507@sirena.org.uk> <672e8d77-ee5c-f10f-0bd3-f8708dfc24c8@devtank.co.uk> <20210423162055.GE5507@sirena.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210423162055.GE5507@sirena.org.uk> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 23, 2021 at 05:20:55PM +0100, Mark Brown wrote: > Part of the issue here is that there has been some variation in how > num_chipselect is interpreted with regard to GPIO based chip selects > over time. It *should* be redundant, I'm not clear why it's in the > generic bindings at all but that's lost to history AFAICT. It seems num_chipselect is meant to be set to the maximum number of *native* chipselects supported by the controller. Which is overwritten if GPIO chipselects are used. I failed to appreciate that when I changed num_chipselects for spi-bcm2835.c with commit 571e31fa60b3. That single line change in the commit ought to be reverted. And the kernel-doc ought to be amended because the crucial detail that num_chipselect needs to be set to the maximum *native* chipselects isn't mentioned anywhere. > The best thing would be to have it not have a single array of chip > select specific data and instead store everything in the controller_data > that's there per-device. Unfortunately that's non-trivial. The slave-specific data is DMA-mapped. It could be DMA-mapped in ->setup but there's no ->unsetup to DMA-unmap the memory once the slave is removed. Note that the slave could be removed dynamically with a DT overlay, not just when the controller is unbound. So we'd need a new ->unsetup hook at the very least to make this work. The Foundation's downstream kernel now contains a bandaid commit which raises the limit to 24 and errors out of ->probe if the limit is exceeded. I would have preferred if it errored out of ->setup. That way only the slaves exceeding the limit would fail to instantiate: https://github.com/raspberrypi/linux/commit/05f8d5826e28 Thoughts? Lukas