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=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 30B22C433FE for ; Thu, 10 Dec 2020 17:40:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE61B23A33 for ; Thu, 10 Dec 2020 17:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392699AbgLJRP0 (ORCPT ); Thu, 10 Dec 2020 12:15:26 -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-Google-Smtp-Source: ABdhPJziR/l9hhuz4i79b1jrE7m+PakJEztwfbuwD6PXsgOpr9F7MTjEh1gT0GgRu7hbNFVGhxP+FA== 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()