Received: by 10.192.165.156 with SMTP id m28csp1218970imm; Wed, 18 Apr 2018 06:14:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48FCrUbq5Omk/55ewtDHVm04D/q0W8lB+t57PwFXmHALgVYMBoA4KXBIMatvhPeEZAQtwZX X-Received: by 2002:a17:902:9a49:: with SMTP id x9-v6mr2041317plv.94.1524057285822; Wed, 18 Apr 2018 06:14:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524057285; cv=none; d=google.com; s=arc-20160816; b=ekgwO8yI1zaN/cQZA1fT8ASCP3lh0eZWxWA/9cEQVlzn9/iSVtJTImXQFn1aLNF0iP fc0gQlxamZxxKye293z0XyjvfPlMghwh8Jxui31y3wkrQOTyQ6HlZBe/EDn/n8GnXN+q M+IHkf7kc8UNOuHnL5NLklnm5cGFYaA9YzQe7GZaXlNh/BCJ57z46VIh8tibFuSOcBvD TYTsf5k7ZuSNo7o27rQuZ+HEToDDftkcjBdJmR02Km2+thkFsONgVaifenxWKSyOPiAv t/fmjMm47KTf6k9zHVijUx2qH0yS8Du5dEOkyh/pMJiGkjqiJvko3yOZ9iSLiRs4rTdn XALQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Kvy2qqajnj2+CmS7J2HKCAH9Ro/GWgo3ZMVVFyyyPME=; b=LkWy1cODwawmhRIld5no+KN4tsxJ4+rp/G1Auny7rw/7BRH259zreodFl3xltSn4Da WL2kNjzdDwlQnjnnsemMauO4nPWQ5jkNPD0zEhsKnar4AvfL5wKpcXw7c6FT4kElh4q+ cTB0TjHArkZNn+lRM5d3jIGGWsWedIhIif4PWCTva1T8Ocf2vtHltJ1bBr9n8J9wYWPk E1BzRxEF3d1hcEdX5vLJLJDtV7JonTP4eqOFKnLKzpHR2Ii+ATGEbLWneyr2q/Khq/ct W+CNKrBqa4ne4kWzuyJqUqydGlPcqKTBiBZS62u4kYqxa2DGyYRgu2xyGQgcKo7/KjZ0 j00Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si1151412pfs.45.2018.04.18.06.14.28; Wed, 18 Apr 2018 06:14:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753763AbeDRNNV (ORCPT + 99 others); Wed, 18 Apr 2018 09:13:21 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:49221 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752617AbeDRNNU (ORCPT ); Wed, 18 Apr 2018 09:13:20 -0400 X-Originating-IP: 2.224.242.101 Received: from w540 (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 1A5921C000B; Wed, 18 Apr 2018 15:13:16 +0200 (CEST) Date: Wed, 18 Apr 2018 15:13:14 +0200 From: jacopo mondi To: Christoph Hellwig Cc: Jacopo Mondi , ysato@users.sourceforge.jp, dalias@libc.org, thomas.petazzoni@free-electrons.com, robin.murphy@arm.com, geert@linux-m68k.org, linux-renesas-soc@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sh: mm: Fix unprotected access to struct device Message-ID: <20180418131314.GC3999@w540> References: <1523972123-5700-1-git-send-email-jacopo+renesas@jmondi.org> <20180418104703.GA12462@infradead.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="yudcn1FV7Hsu/q59" Content-Disposition: inline In-Reply-To: <20180418104703.GA12462@infradead.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --yudcn1FV7Hsu/q59 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi Christoph, On Wed, Apr 18, 2018 at 03:47:03AM -0700, Christoph Hellwig wrote: > On Tue, Apr 17, 2018 at 03:35:23PM +0200, Jacopo Mondi wrote: > > With commit ce88313069c36eef80f21fd7 ("arch/sh: make the DMA mapping > > operations observe dev->dma_pfn_offset") the generic DMA allocation > > function on which the SH 'dma_alloc_coherent()' function relies on, > > access the 'dma_pfn_offset' field of struct device. > > > > Unfortunately the 'dma_generic_alloc_coherent()' function is called from > > several places with a NULL struct device argument, halting the CPU > > during the boot process. > > > > This patch fixes the issue protecting access to dev->dma_pfn_offset, > > with a trivial check for validity. It also passes a valid 'struct device' > > in the 'platform_resource_setup_memory' function which is the main user > > of 'dma_alloc_coherent()', and inserting a WARN_ON() check to make future > > (and existing) bogus users of this function they're should provide a valid > > 'struct device' whenever possible. > > Please fix those callers to not pass a NULL pointer instead. As long as it goes for arch/sh, the only user of dma_alloc_coherent() is platform_resource_setup_memory(), and it has been fixed by this patch. Unfortunately, as Thomas pointed out, there are drivers which calls into this with the wrong 'struct device' as the sh_eth one he had fixed. I would then say that as long as it goes for the NULL case, we should be fine now. Thanks j --yudcn1FV7Hsu/q59 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJa10RqAAoJEHI0Bo8WoVY8Yd0P/iiNRjagfqzMP1IsC2KW4DjU NNDYLQdjp8rNwfpHKnIUHe1L40bramSe6FbaKIIFyAjoZfQX+6AKwU23wPbf7P6j NjSj1Vh/jMLeDIrGIWVslHHQ3fJ6UMm39h178sMJBDxRwFsdTYWqFmKHTkpWU+9C mlEq7TT1k9C0u94VfK/2bCy88ndqxImW833OWcAuCmXpAiwr1Jq+0pptF1Z8g2eV asXaTpxUebeqOvar3o7nszlQFJL8NWBg64BVFPZz96j601XHVOhziQcp0Yy3H8D6 OTvG6qB+4v3izbWU5T8U9lOJ4GlmyWaf0RmIEf+SxYU2zRnd18w8r4o2p10ho/SI zt8KlLlzRkJH9ZM+H55LrT76OuXGoKvIqmaLaRcFS8PWe+yMKgoUura/E/SqyEsR 6qhehCshVaROUXn94HPP5UOT0NgE7XLcr6/bVj8Vkpr1K0L33qk6KyQHf/h8vTc8 xgYkg8D3AQrh3YR5dJhmfmj6lUeGfFI84DW6teIctss+XBnMW2JUgCLWbUTM/hSP ZFCsrtfhrU11y82o7GXRKoyp5qci4iGuAkqyrImJdyD2YVbpyrSvPvpVgpvGiEHi 8rUHUfnf3/5OHA1rdMhY42RSntuXvuINjyrzDeLuof7KaeHqKDN0o3hpcPUranaA is0I+gj6irYVukOtcQTs =e52k -----END PGP SIGNATURE----- --yudcn1FV7Hsu/q59--