Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp300108ybh; Wed, 15 Jul 2020 02:14:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1hpYGmTeorVHO1FqBv3WHUu9VJUz1Lcsg+wPmAtQKeDX4JKRE9hadL0ldEpVnkBrDKMf9 X-Received: by 2002:a17:906:924d:: with SMTP id c13mr8081741ejx.518.1594804488907; Wed, 15 Jul 2020 02:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594804488; cv=none; d=google.com; s=arc-20160816; b=Z391ZoqlThbX+Ss2AsEYApjjrvrGu0uJQd28xeFcTvqHZ47Ubj2wPbNpNdpL40oLb1 GLpOOEQvcZLQSwmGfHTKkp+GZLVVoVCERnSvOfKdvD4Baf2XnY5c5jUaSrMvBkjEnu8F ZgQl5/732h19MlqcYwEd9R1HV/To1RDSOUelcAqIB2apFxBErS+iHIOgpH717ROSm6NI lh5RNRPwXExOhj1dfmg3niNcHBQrmqaJHRJFMiwhL2TjSZ6Fa1KR1bdn75LUU+GDZeMs XjxrW2qHIAko2S8/BYjsIgLO5ODIRcbeXcxD4F1q6s8mYi6ng8d+pehtUrwCfphaCeTe ikVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=3xiQ0vTDOSTESSN096aBDlKYmYjzrdf/LhVyTEamGSc=; b=Z8BC/bl+iJocRjvvBHlwHSd+Kjyx/CYaPb+b2nMLxNgI2SZfobzcNpuRi+i1UM9Ka6 kTyLJ79UjJd40zKU+f7CK5PnulVQjpVv0a49P5Bw3bhFvw8jY5fG1lW2aVKfjn94kJDk Of24UMgDWrzYkr1OZETAkpF5rLxBm93ElN8I4jXqeV/U0dQzjwWLhuXYIsOemNhSVlLH bqQ3ZzmajhtxEYFhd/0hCUpzRZqIFSROmRhv/XvqO9QjaDzmoQyqiHaORCo9YBikhZxp OME1JO0TMQDFQGlaq1Vp1DfNyOiLoRlNjbsojxyrQCXl3ACoMMTt4bfiW2kvhgMIZiiD k2mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=nc7TV2jL; 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si950211edx.522.2020.07.15.02.14.25; Wed, 15 Jul 2020 02:14:48 -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=@nvidia.com header.s=n1 header.b=nc7TV2jL; 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730386AbgGOInv (ORCPT + 99 others); Wed, 15 Jul 2020 04:43:51 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8674 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729377AbgGOInu (ORCPT ); Wed, 15 Jul 2020 04:43:50 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 15 Jul 2020 01:42:52 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Wed, 15 Jul 2020 01:43:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 15 Jul 2020 01:43:50 -0700 Received: from [10.26.73.219] (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 15 Jul 2020 08:43:44 +0000 Subject: Re: [PATCH 2/2] usb: tegra: Fix zero length memory allocation To: Thierry Reding CC: Mathias Nyman , Greg Kroah-Hartman , , , References: <20200712102837.24340-1-jonathanh@nvidia.com> <20200712102837.24340-2-jonathanh@nvidia.com> <20200714093256.GG141356@ulmo> From: Jon Hunter Message-ID: <9c8ddf99-40fb-547f-81a9-05f0c64c9a5f@nvidia.com> Date: Wed, 15 Jul 2020 09:43:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200714093256.GG141356@ulmo> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1594802572; bh=3xiQ0vTDOSTESSN096aBDlKYmYjzrdf/LhVyTEamGSc=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=nc7TV2jLCSjE3pSrrGfu/3q01u0z0h9PWL0U6XakGVGY4UqrVPyuW4xTolcE0HET4 9qp+6VYCgB2I9PqGZaNwqVVNMmtnrC14xan6oxdDMn9q+sx7+8EGXr1cgOFN4KKcdQ vXfNKcIxRyn6hkm/FOHJw2GHkYQ7TVJi3Yfu9cluLqu67f5fkRnbT2NtX7NPw87phJ CXKKVCd8ZVY+UeHBD+bz7iaM7/nPk3s+pVuV3hDpocPthL+c0980bsGJOTmrrUAvqb bhAjyMx2jZvFR8DnFPpDUggd5+451h4klTBbtIZY4hkJxi2knFNDqCJ0orF0ZiUsD+ f2UXlqXmCR4ZA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/07/2020 10:32, Thierry Reding wrote: > On Sun, Jul 12, 2020 at 11:28:37AM +0100, Jon Hunter wrote: >> After commit cad064f1bd52 ("devres: handle zero size in devm_kmalloc()") >> was added system suspend started failing on Tegra186. The kernel log >> showed that the Tegra XHCI driver was crashing on entry to suspend when >> attemptin the save the USB context. The problem is caused because we >> are trying to allocate a zero length array for the IPFS context on >> Tegra186 and following commit cad064f1bd52 ("devres: handle zero size >> in devm_kmalloc()") this now causes a NULL pointer deference crash >> when we try to access the memory. Fix this by only allocating memory >> for both the IPFS and FPCI contexts when required. >> >> Cc: stable@vger.kernel.org >> >> Fixes: 5c4e8d3781bc ("usb: host: xhci-tegra: Add support for XUSB context save/restore") >> >> Signed-off-by: Jon Hunter >> --- >> drivers/usb/host/xhci-tegra.c | 22 ++++++++++++++-------- >> 1 file changed, 14 insertions(+), 8 deletions(-) > > Actually it would seem to me that this is no longer a bug after your fix > in patch 1. We only ever access tegra->context.ipfs if > tegra->soc->ipfs.num_offsets > 0, so the special ZERO_SIZE_PTR case will > not actually cause an issue anymore. > > The reason why this was crashing was because tegra->context.fpci was > allocated with a zero size (because of the bug that you fixed in patch > 1) and then that zero-size pointer was dereferenced because the code was > correctly checking for tegra->soc->fpci.num_offsets > 0 in the context > save and restore. > > So I don't think there's a bug here. It's not wrong to allocate a zero- > size buffer. It's only a bug to then go and dereference it. Are you > still seeing the issue if you leave out this patch and only apply patch > 1? Ah yes you are right. OK, we can drop this. I will update the commit message to patch 1/1. Jon -- nvpublic