Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4476892pxu; Wed, 9 Dec 2020 19:20:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwD3G7cPirKtF+r5EPJBwLE4WOk5ZQIFBvAa6KSo5qQgtm5hBChAJmBJ+hrP9UKg/AxdosK X-Received: by 2002:a17:906:d87:: with SMTP id m7mr4672173eji.108.1607570426031; Wed, 09 Dec 2020 19:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607570426; cv=none; d=google.com; s=arc-20160816; b=qmnIbYuiZZr79h1cVHgEX2fodQ/WfofDCCHB+a54E3fRIYv2mG87jFrVf/NnzEg/aT 5ob7pcbeCX7Gr7bBhjm2CIgPZsJXhcCzHPBiLqFVthsDTlKPuNFeKOAc8puRray+HhMt HfjYy9lUwsxbOdjSlLb57QifKCJBbgret/k+e49QvOJNlCvVkToOhdcp2XsyvR02KXak 60eYgty/nXwhPGX4aUt5TiiGnA4/hTCFX6/VsLIIs1Agc85GZJvVGdVJWavw3Hyy1Juq 5DC7QdJ0+13b1otb3lnwM48mWaA/BbEzXEaJfRI8kbDsf6y5hFEwQHBCxebjR5W8mw7R TnUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:date:to:cc:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=k53PFT7deXWzGUQq0Qpf6W/21ZGbwiD77Sh9ifdNlYI=; b=vO9Xiv3qlmzKPr5T4gvRwvtCELV/ugNvAREciufZ6yNGHb/yvInX3WHNHA8rtZMNeY gh6thCR/erteyAj0YpHiTLAjjBGFJoWEgmq3m13Xk90nys89S9Q4FwC5jAg6qptDUjPc OgoL1l6k/Xiq5gSzUdbSm2qDJhL2i0wChpZNEGMGk0YMXfZilmcasi0N7bhAGn4hJ85A yNTadASVF/X+MqS2s7SaKY1dvGtyQUCjeDIoNe4/F3+O2alERjwIqsKG/0grqUcwElx7 5iKIs0XYU9dkM6x+QIfJkZ9lMxpCLutIMokqnZQn0Gs1wBCd7GZI6Y6vlhH76Us+JRZK Jm5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="j/3AaR7R"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m12si1773333ejr.608.2020.12.09.19.20.03; Wed, 09 Dec 2020 19:20:26 -0800 (PST) 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=@chromium.org header.s=google header.b="j/3AaR7R"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729165AbgLJDRn (ORCPT + 99 others); Wed, 9 Dec 2020 22:17:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728619AbgLJDRn (ORCPT ); Wed, 9 Dec 2020 22:17:43 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20D3BC0613D6 for ; Wed, 9 Dec 2020 19:17:03 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id t6so2072097plq.1 for ; Wed, 09 Dec 2020 19:17:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=k53PFT7deXWzGUQq0Qpf6W/21ZGbwiD77Sh9ifdNlYI=; b=j/3AaR7Rv5E0+fKghUnWh6A8a2UeZzPe81/mLS/v3NuwDplaOQN7T01j81j978t12h Bv9RlbNJWBBugNdKcx8NNnfildF6mmoJj0b92N2lH5GxU6SKQMNwTH9JTvNBpLJpl87c ZbfOQwyLx35Nuie38/uNAF48DHT4i+K8moLJo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=k53PFT7deXWzGUQq0Qpf6W/21ZGbwiD77Sh9ifdNlYI=; b=QYtIBFtIzYa3af+RlaUz2VlaM5VIARWrK+JUFZ2X9iCaKU/erY+mrUAhGHzwS8UDCv CGRBuThA83UqEBQb3s38LKnxiz1oKqeGbf+b2x8KHZg4DGfAQg4md6kKgPakRL96chvT jc+NFNFxYArf8NOAmcZ2ZvI2nUhnVkTagrVYS2TGSFLwyWoabTegcDlqzTVsM2D/6KBo qAblsH4IvAoyx6LgHdOydppw3zNIfQxVJfIF2vwTFAh3QSOjRJ0MmDL1hwYlWL4YgnvO 4a/TzgEDZBZVR1d0Jwdm5UUOixJRyTIzQOycFHBp587KMvdEkqW94Iz8i9kE2Rvt0m2E QQhw== X-Gm-Message-State: AOAM531lpoajePNw2Fhhtw/8greucc9DHIu0dui57Gju7AE9CtlzmBHm HS6Rvne5ZHdEv0saX90DvyN8MA== X-Received: by 2002:a17:902:74cc:b029:da:9287:2b4 with SMTP id f12-20020a17090274ccb02900da928702b4mr4650468plt.9.1607570222586; Wed, 09 Dec 2020 19:17:02 -0800 (PST) Received: from chromium.org ([2620:15c:202:201:3e52:82ff:fe6c:83ab]) by smtp.gmail.com with ESMTPSA id l17sm3665289pjy.29.2020.12.09.19.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 19:17:01 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20201203074459.13078-1-rojay@codeaurora.org> Subject: Re: [PATCH] spi: spi-geni-qcom: Fix NULL pointer access in geni_spi_isr From: Stephen Boyd Cc: Mark Brown , Andy Gross , Bjorn Andersson , linux-arm-msm , linux-spi , LKML , Akash Asthana , msavaliy@qti.qualcomm.com To: Doug Anderson , Roja Rani Yarubandi Date: Wed, 09 Dec 2020 19:17:00 -0800 Message-ID: <160757022002.1580929.8656750350166301192@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Doug Anderson (2020-12-03 08:40:46) > I would guess that if "mas->cur_xfer" is NULL then > geni_spi_handle_rx() should read all data in the FIFO and throw it > away and geni_spi_handle_tx() should set SE_GENI_TX_WATERMARK_REG to > 0. NOTE: I _think_ that with the synchronize_irq() I'm suggesting > above we'll avoid this case, but it never hurts to be defensive. >=20 >=20 > Does that all make sense? So the summary is that instead of your patch: Can we get a CPU diagram describing the race and scenario where this happens? Something like: CPU0 CPU1 ---- ---- setup_fifo_xfer() spin_lock_irq(&mas->lock); spin_unlock_irq(&mas->lock); mas->cur_xfer =3D xfer ... geni_spi_isr() geni_spi_handle_rx() But obviously this example diagram is incorrect and some timeout happens instead? Sorry, I'm super lazy and don't want to read many paragraphs of text. :) I'd rather have a diagram like above that clearly points out the steps taken to the NULL pointer deref. >=20 > 1. Add synchronize_irq() at the start and end of > handle_fifo_timeout(). Not under lock. >=20 > 2. In geni_spi_handle_rx(), check for NULL "mas->cur_xfer". Read all > data in the FIFO (don't cap at rx_rem_bytes), but throw it away. >=20 > 3. In geni_spi_handle_tx(), check for NULL "mas->cur_xfer". Don't > write any data. Just write 0 to SE_GENI_TX_WATERMARK_REG. >=20 > I think #1 is the real fix, but #2 and #3 will avoid crashes in case > there's another bug somewhere. >=20 Aren't 2 and 3 papering over some weird problem though where irqs are coming in unexpectedly?