Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4971927pxu; Thu, 10 Dec 2020 09:44:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbJ2hQLxkRwQ9PtiYs7tsn7ewIWpEUO5juctt2/CSjs8IRjNIBvX32jWwSdUMjUJh2PHBR X-Received: by 2002:aa7:c388:: with SMTP id k8mr7852685edq.36.1607622243501; Thu, 10 Dec 2020 09:44:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607622243; cv=none; d=google.com; s=arc-20160816; b=VpUp+onyhVRXAshEqzxyEFlauD0CxHOdY+mNk5d2Z5OMUysMXMGExdslzwsfSDU7x5 IItT1668qX7bHtVH3ZfxORCxTYq/P6gogaQ7xlnX1Dj4tklM93W8tRiXY6sy5pUMn9WP x29QxVH/FA9rItQ/DnVaAS2zMyAL+UiViebOZgq6ZVUSNr/w8HvOmaOSeTICxLIunXVJ kklexH0fkCepI3C9bWvPcvaNXbzK6NML9v6GeTFtncirGqQXr8qsQxiQ8ytnX8GbIeK9 4kmhbTvXT4eOSc7NhRwzEZXMLxHa+tCMscCwzOTUumVDeJC3NWqYs+iV1NYmBI3I4Ey6 vMFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xMgQPzANQdeOqMY+fXyJVOEZa71a65TdMFizwM/N9b0=; b=uJjt2pWGW6gRuvF9SMmWH3RuakfClhXtOuBCJuxBqmLBair0joFMP49VSNW+DgSDPK YjC8FN9ycrEZys7fqvic3h3sXZW6pt6O7nr8A5yYbbiQhdLWyx4GKSMq2hyFviJlTI56 6XPuV2JtZ+gSAvw9IsxNvV2DPyfz9ltexr8CoDHP5b3/DxzciTCqXKd+ZH0yqwHcERTP G1ws3/K6XyyL1cOhJ0VCa5vc/ggVLQpiRk+3IRdRTyohPxc0J4IkAH4xGDSifxHWEdy4 DUOJ8hy23GtfkuJ3QlPfpuyQOHIsyb83pDVqop4dVQJSHJpVdmCEDl3/hbzpMsQPwKlh 69HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="WnikWqu/"; 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 r19si2924620ejz.538.2020.12.10.09.43.38; Thu, 10 Dec 2020 09:44:03 -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="WnikWqu/"; 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 S2392671AbgLJRPS (ORCPT + 99 others); Thu, 10 Dec 2020 12:15:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392651AbgLJRPK (ORCPT ); Thu, 10 Dec 2020 12:15:10 -0500 Received: from mail-vs1-xe42.google.com (mail-vs1-xe42.google.com [IPv6:2607:f8b0:4864:20::e42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2525FC061793 for ; Thu, 10 Dec 2020 09:14:30 -0800 (PST) Received: by mail-vs1-xe42.google.com with SMTP id v8so3255577vso.2 for ; Thu, 10 Dec 2020 09:14:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xMgQPzANQdeOqMY+fXyJVOEZa71a65TdMFizwM/N9b0=; b=WnikWqu/v1U0viE/wvjK6QZAW6WMiIGtgjXOrFJM+gR4YgZklzOOU/3A8DYKZRjnvZ /KqbvstT7mebzyo7tqJPILPN8Rt1PlqqIB0GFGSeFC2zpLhD7d9cxFeoYc9hsbVOUQqE N9dRWSWNxoK4zG9RdmRRpq8Q0VxyW6mOw60ac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xMgQPzANQdeOqMY+fXyJVOEZa71a65TdMFizwM/N9b0=; b=Z47j8oIt1eXX/Cw6WO59eYC6CnZy4jE+8EJHnziGoTS3mILaITSy0nuN7MPMbPtLog NKaQxUp2t9X7Ef1a7uVgRGUfXF0AnyMVQiuUwgGSNtLeqCn+MCc9J5KiYJ0e3CdneOpO iBb9Bl9Qm1ww+hjtZcLv5nzc8OhXB7W2HvKfcceZRV/EOPgJdMJl+x5GDMeJui1qiTPB VODG5hvy00whtHwVfQjaOO2gaO8tbGUt+cpjGAvqtTz+zdXDKrISa3i478L2JRnkARZn UCkfySSxHev15Cqu4RGbjGMtCQB8XerW49Cv5coKQEcv7bihZm5eNwgShrgQl1Ao9pvC fcow== X-Gm-Message-State: AOAM5323n0gbfQJt6lAGbzftWd8OTSwjIZBfMIdCVd1QxKcGwAAXmQj1 mh3eDlQewraYOuHGQ4IEZlGJLi4V0HEg+Q== X-Received: by 2002:a67:bd01:: with SMTP id y1mr3062136vsq.49.1607620468967; Thu, 10 Dec 2020 09:14:28 -0800 (PST) Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com. [209.85.221.176]) by smtp.gmail.com with ESMTPSA id a66sm593424vka.23.2020.12.10.09.14.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Dec 2020 09:14:28 -0800 (PST) Received: by mail-vk1-f176.google.com with SMTP id a4so1391090vko.11 for ; Thu, 10 Dec 2020 09:14:27 -0800 (PST) X-Received: by 2002:ac5:ce9b:: with SMTP id 27mr10106859vke.9.1607620467257; Thu, 10 Dec 2020 09:14:27 -0800 (PST) MIME-Version: 1.0 References: <20201203074459.13078-1-rojay@codeaurora.org> <160757022002.1580929.8656750350166301192@swboyd.mtv.corp.google.com> In-Reply-To: <160757022002.1580929.8656750350166301192@swboyd.mtv.corp.google.com> From: Doug Anderson Date: Thu, 10 Dec 2020 09:14:15 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] spi: spi-geni-qcom: Fix NULL pointer access in geni_spi_isr To: Stephen Boyd Cc: Roja Rani Yarubandi , Mark Brown , Andy Gross , Bjorn Andersson , linux-arm-msm , linux-spi , LKML , Akash Asthana , msavaliy@qti.qualcomm.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, Dec 9, 2020 at 7:17 PM Stephen Boyd wrote: > > 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. > > > > > > 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 = 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. This is my untested belief of what's happening CPU0 CPU1 ---- ---- setup_fifo_xfer() ... geni_se_setup_m_cmd() spin_unlock_irq()