Received: by 10.223.185.116 with SMTP id b49csp4094111wrg; Tue, 6 Mar 2018 09:41:36 -0800 (PST) X-Google-Smtp-Source: AG47ELv/QfpmyWvjyPKsOxw2Msms0LNvKAvxcEokK47efVUrLf6OfYdLNkeIrOavl29oW/OxlkNH X-Received: by 2002:a17:902:6a89:: with SMTP id n9-v6mr7115538plk.51.1520358096106; Tue, 06 Mar 2018 09:41:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520358096; cv=none; d=google.com; s=arc-20160816; b=ukb3WME4wGOU7piEAFqaA0bIpp+IldfPlIh1+lLtoeUmjhuIGi2oUBnVkvBS+hDT3l ULsQPSz+fJdsByoB4c20GYcC1kAS3NNSAB3+YcRcaoFOP6anjkB5Qo0R0OmWIzVD0RAH XBXnNep5jnspmSnBdK4N34UXpMaWb7wH2elTZfOLX0AibJlF0U+8SsUeD8tv9GaXabHL X4hQzQ9AU76gvKn4Had9tuBQFnRGsm2In0z+lDdrTeBr3DUX2lU/3PEwAFOF67JaZelI bywLjn8iFZRJ+zrX4t/w/eV+d137UDg9otFeX8Q2cSbq8nqG9QpBsgnfeaX5/+tPJHmB eCQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=seGI/jKkjMKBT1amFCdCvdmsurDRoTFTARmqcQoAhkg=; b=K+97kXS4BIyAyK7qIEhbyy7aW/8TjnBqMnYzLfcr0g9YrbhINyn+iZImeNdMYl2DVo qUvYT+Zv21AdhWZtvBAk45c1rZQ5fWj6L6kaJ3JGEGZ9EFAFXpcoNIl+NdsgpTrE/bJp Hd/bW+yfG66kHwBaN/V+e/IeXSBjUe3ka1L1o40IbPRXE7Da4VOdSxTI3mS5JVVcMotg EyQbLMvwAx8A8RiSA9p08txlvxfmNFoT4pq8KqnAFI/NbZlGqt0FA5iPtOxSo/JKSXeW Qtg6VQQ53PtUqNLa77pACEcmupfscPBE6b0DXnfkP5pXtYMFHuhkwowBPB4jZMqnhm4M PBRQ== 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 e4si10086573pgp.516.2018.03.06.09.41.20; Tue, 06 Mar 2018 09:41:36 -0800 (PST) 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 S1753930AbeCFRjq (ORCPT + 99 others); Tue, 6 Mar 2018 12:39:46 -0500 Received: from lhrrgout.huawei.com ([194.213.3.17]:28469 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753891AbeCFRjp (ORCPT ); Tue, 6 Mar 2018 12:39:45 -0500 Received: from LHREML713-CAH.china.huawei.com (unknown [172.18.7.107]) by Forcepoint Email with ESMTP id 06822D36B3B9C; Tue, 6 Mar 2018 17:39:41 +0000 (GMT) Received: from [10.202.185.64] (10.202.185.64) by smtpsuk.huawei.com (10.201.108.36) with Microsoft SMTP Server (TLS) id 14.3.382.0; Tue, 6 Mar 2018 17:39:41 +0000 Subject: Re: [PATCH 1/7] genalloc: track beginning of allocations To: J Freyensee , , , , CC: , , , , References: <20180228200620.30026-1-igor.stoppa@huawei.com> <20180228200620.30026-2-igor.stoppa@huawei.com> <6a31164a-af3f-91ea-d385-7c6d1888b28c@gmail.com> From: Igor Stoppa Message-ID: <05bde73d-6c0a-8309-4150-7225862c28e0@huawei.com> Date: Tue, 6 Mar 2018 19:39:41 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <6a31164a-af3f-91ea-d385-7c6d1888b28c@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.202.185.64] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/03/2018 21:00, J Freyensee wrote: > . > . > > > On 2/28/18 12:06 PM, Igor Stoppa wrote: >> + >> +/** >> + * gen_pool_dma_alloc() - allocate special memory from the pool for DMA usage >> + * @pool: pool to allocate from >> + * @size: number of bytes to allocate from the pool >> + * @dma: dma-view physical address return value. Use NULL if unneeded. >> + * >> + * Allocate the requested number of bytes from the specified pool. >> + * Uses the pool allocation function (with first-fit algorithm by default). >> + * Can not be used in NMI handler on architectures without >> + * NMI-safe cmpxchg implementation. >> + * >> + * Return: >> + * * address of the memory allocated - success >> + * * NULL - error >> + */ >> +void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma); >> + > > OK, so gen_pool_dma_alloc() is defined here, which believe is the API > line being drawn for this series. > > so, > . > . > . >> >> >> /** >> - * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage >> + * gen_pool_dma_alloc() - allocate special memory from the pool for DMA usage >> * @pool: pool to allocate from >> * @size: number of bytes to allocate from the pool >> * @dma: dma-view physical address return value. Use NULL if unneeded. >> @@ -342,14 +566,15 @@ EXPORT_SYMBOL(gen_pool_alloc_algo); >> * Uses the pool allocation function (with first-fit algorithm by default). >> * Can not be used in NMI handler on architectures without >> * NMI-safe cmpxchg implementation. >> + * >> + * Return: >> + * * address of the memory allocated - success >> + * * NULL - error >> */ >> void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) >> { >> unsigned long vaddr; >> >> - if (!pool) >> - return NULL; >> - > why is this being removed?  I don't believe this code was getting > removed from your v17 series patches. Because, as Matthew Wilcox pointed out [1] (well, that's how I understood it) de-referencing a NULL pointer will cause the kernel to complain loudly. Where is the NULL pointer coming from? a) from a bug in the user of the API - in that case it will be noticed, reported and fixed, that is how also other in-kernel APIs work b) from an attacker - it will still trigger an error from the kernel, but it cannot really do much else, besides crashing repeatedly and causing a DOS. However, there are so many other places that could be under similar attack, that it doesn't seem to make a difference having a check here only. If the value was coming from userspace, that would be a completely different case and some sort of sanitation would be mandatory. > Otherwise, looks good, > > Reviewed-by: Jay Freyensee thanks [1] http://www.openwall.com/lists/kernel-hardening/2018/02/26/16 -- igor