Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1398608pxy; Fri, 23 Apr 2021 07:14:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxq0+ShzGL5Z6wVdxFVMpqSZlcX9ja2ov1+O+S9QuYnT8tE28vMTVcvqYRs8RoOUJwkyI1 X-Received: by 2002:a17:90b:392:: with SMTP id ga18mr5806175pjb.222.1619187265889; Fri, 23 Apr 2021 07:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619187265; cv=none; d=google.com; s=arc-20160816; b=gD9/8ob8aR7qeo4ytSnAosqpb5ECBrD5dlxNSf2u2IuD3cz1Fit7dAXmqYeNs5Md48 lnKvKIFvzWqtAzUnXXaANBWE+4ScGFXCfMr2OWrriGL+rnDYaZIH14mu8VvRbk8DAm/1 CRJCwOJMcDOIU46wL0a8zYAjQDIbnEy7m3G+e+3Bgs3mknViTjuuwwTr/GOKEz/yzowJ drk/Lry3f7VqPBew0dmuMiIjSONGFdcM+HaeBAsPJ+PN6/hu2Si6xLDiZ9RGVU3PV1KC s4Fc4j3WiTJ2R+6f9SSymn+K+/1ALmwQRrYJ5Yotps4uNDPhcxvdasuE/KiWSG124mlu EJbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=CU0yuJS9gxaSOduT5DnrFoz0/Pq9Ku7rhLu8n8w6dEQ=; b=f1CO3Ic+y5klTyJFQDXZpQq5u6Y1jKtiFOlhdZm3d/iLad7/QAl35ngGYcbsjx4yuy VSjrC7s7YWuITBZ7YxErSEcVlnE1Hi2M+hybcbsFFJRhsqBwRgUdeZ0081rOMTC6QzOK lIyq1VUQ3AxEgKsEFa88bOZOcqL1rCAsUU5Fk7Ph9P6wYsMbQvWLb/WToQuDI4j4xiit OgYxj/E9uFAwBsA0uLvZ++tELgMyYqht5uDtjBzI1t58WIJkIgnOEt9h9raqOi6Rf3b1 3uoz6mmvjLGRRGoftxX0xVsjQU7Oe+5BmoSuGddV8Hq3QZuYJKFzVPST+dySfwrCSdqO cnbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@devtank-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=FjcMFAiC; 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 r140si6539971pfc.8.2021.04.23.07.14.13; Fri, 23 Apr 2021 07:14:25 -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; dkim=pass header.i=@devtank-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=FjcMFAiC; 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 S231585AbhDWOMv (ORCPT + 99 others); Fri, 23 Apr 2021 10:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbhDWOMu (ORCPT ); Fri, 23 Apr 2021 10:12:50 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16940C061574 for ; Fri, 23 Apr 2021 07:12:14 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id i21-20020a05600c3555b029012eae2af5d4so1319290wmq.4 for ; Fri, 23 Apr 2021 07:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devtank-co-uk.20150623.gappssmtp.com; s=20150623; h=to:cc:references:from:subject:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=CU0yuJS9gxaSOduT5DnrFoz0/Pq9Ku7rhLu8n8w6dEQ=; b=FjcMFAiC2Nzpzw2fgx4R7R4Ayv9f1f1mFWIV68T6kRA9aCFsYDjKJe3lYN+Wtnb+Bi tv70qgnADNyPnBXTx9QgyNgWVvsEXful5jnEg8aAiE0DnnFpDaDtfRK0WMiUvS1OBuVZ YUxW5ugHFa8VqJ5zkT1tLg7sOgQuIyZ9HabaL5RxFaSH6HxJWAdEu0oT4abXnbw2BrJY gce99n3TnU2B2XFjohjlk6B/TXsgkTvUywf3mYjp7uKYRw+a4yyTFczj5I38zVUP+eqc /4YSiRDed7pPOe104yond7mK/E4a5Rvctl/sVovxZSMCHq9UTY2HBS2zEVNcw+hlaOf+ f3MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=CU0yuJS9gxaSOduT5DnrFoz0/Pq9Ku7rhLu8n8w6dEQ=; b=hplS6vReseyDI9JU/r60ZIkn23vYx4uqRaMWwzI/oAWOBKKeFY1je+CIZ4RnntyHE7 iGzX0tmZoqqNXbdpH5dZbAqHfCIv/H+JVrurykqBM2tnDZ7Dj+A6HZ0gMBXuU7zcqbrq AQqT8gh0I/Alpl5yt6U5e+ZngzaHZCQ9Q6A7tgpQxaI7txvm+VC/z4WJ84nt1ubXdlej nmX6I4OasEGJ+ZIxf1SYbhThX//zUwrj5JJCYijNjhstK393044uamqOMhi4JGZHBbuw g/qA9bLD1r/vFcmdnommQ237mCLUep8j/uvn8rjyiJ7A/UMPFgwKiyIidZaiZEFyFsyc Ztfg== X-Gm-Message-State: AOAM533+XDd1ddXmHzdom0/1cubbgYQsX4+bUpLNSFB9mOMiptk9lXxA dvMndCgD32wLyZhmuJ7wsrkPOA== X-Received: by 2002:a7b:c5c8:: with SMTP id n8mr5858732wmk.63.1619187132828; Fri, 23 Apr 2021 07:12:12 -0700 (PDT) Received: from [192.168.200.229] (static-84-9-134-242.vodafonexdsl.co.uk. [84.9.134.242]) by smtp.gmail.com with ESMTPSA id s16sm10871212wmh.11.2021.04.23.07.12.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Apr 2021 07:12:12 -0700 (PDT) To: Mark Brown Cc: 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 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> From: Joe Burmeister Subject: Re: [PATCH] spi: bcm2835: Fix buffer overflow with CS able to go beyond limit. Message-ID: <672e8d77-ee5c-f10f-0bd3-f8708dfc24c8@devtank.co.uk> Date: Fri, 23 Apr 2021 15:12:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210423115724.GB5507@sirena.org.uk> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Content-Language: en-GB Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/04/2021 12:57, Mark Brown wrote: > On Fri, Apr 23, 2021 at 11:03:22AM +0100, Joe Burmeister wrote: >> On 23/04/2021 00:49, Florian Fainelli wrote: >>> Right, which means that we should probably seek a solution within the= >>> SPI core itself, even if you can only test with spi-bcm2835.c chances= >>> are that the fix would be applicable for other controllers if done in= >>> the core. >> I'm not sure it's possible to do in the core alone. The numb of the >> issue is the core changes ctlr->num_chipselect to what is in the devic= e >> tree and some drivers are cool with that overs quietly stomp memory. > I wouldn't expect any controller to be OK with that? Drivers can store= > per-client data in spi_device->controller_data which doesn't need > scaling (but is also not so helpful if you need to look at clients othe= r > than the one you're currently controlling). I can see a number which certainly wouldn't. Though I don't want to assume that all don't. If we are happy just not letting the core expand num_chipselect that does stop the condition on everything. Any controller that can go higher without issue could them have their num_chipselect set to what their real limit is if this enforcement causes an issue. >> I've got a simple little patch to warn when the core expands >> ctlr->num_chipselect. This warning won't go off in bcm2835 with my pat= ch >> because I am also extending ctlr->num_chipselect to the amount in the >> device tree before the core does that expansion. Hopefully that new >> warning would make people investigate and fix problem drivers. >>>> There is protection in spi_add_device, which will catch extra added >>>> later, but not ones in the device tree when the spi controller was >>>> registered. >>> Not sure I follow you, if we have the overlay before >>> spi_register_controller() is called, how can the check there not >>> trigger? And if we load the overlay later when the SPI controller is >>> already registered, why does not spi_add_device()'s check work? >> I think it might be a RPI thing. I think it is merging in the overlay >> and giving Linux one already merged. > If the overlay is handled by the bootloader then from the point of view= > of Linux there is no overlay - sounds like there's an issue in the > overlay, it should be overriding something that it doesn't? Does it matter if the final device tree was compiled like that in the first place or merge into that by the bootloader? The limit isn't an hardware issue because the bcm2835 just uses any gpios for CS. So hardware like ours with 8 spi chips on the bus is fine. The driver's limit at 4 is arbitrary. My patch for the bcm2835 just compares of what is in the device tree and the harcoded limit and uses the largest. Other drivers do this. Of course we could just raise BCM2835_SPI_NUM_CS to 8 or more if that is preferred. Does seams like the dynamic solution is less favoured. Regards, Joe