From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22BD5C433B4 for ; Sat, 1 May 2021 19:52:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC8EC613B4 for ; Sat, 1 May 2021 19:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231753AbhEATxL (ORCPT ); Sat, 1 May 2021 15:53:11 -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-spi@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