Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6893886ybi; Wed, 5 Jun 2019 08:01:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbcwCke0BFUB809mg+IXz0DxJ0pb/Tv5UpPCzzdWCdhEA/C1kJDO9Kj6A6G+Ce7gZPZsGV X-Received: by 2002:a63:ed03:: with SMTP id d3mr4955858pgi.7.1559746907621; Wed, 05 Jun 2019 08:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559746907; cv=none; d=google.com; s=arc-20160816; b=C8ER/FAGaiFuCzJvuSNXhbw/ac+hjZjAuqA4+yx2ofaPAqqIk2vCQjWts/2PZf0sYd 4CGz3JiJhpmsZ12Pwpuz57vjLoPllqD+MFjZfB8bOGiv9NboNt5laG/fmf3EEEgiECrs TJmIGTiCgmV3Qy3oG7NbNZcBkIsEa2dJdPZucYt+WU0trNEiae7O13a973sO41URwSI3 dkz46W7Q6qDgH3DVZB9zgP0eNenIp1HSrS/BzQnssPWz0IOQUnICyB7UKZi1VZuczdok WU5Dk2WGKWmCFeyAgo23Fa4F0iJZzP+ViwPqQiaLwgcQVFGKjkfAoRW+TQXUw8MwiTWN Nv9w== 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:dkim-signature; bh=JMXXe6AqnjayglXVoDkqd6XGPAOEachog6ijJh1WH/M=; b=ZRhr7nuNtJ2qe2iCEC9SWjS7ESyj7ibXMS0gP4cEySI3NqnRdl0mRyqYXvTYXUfuAa LPLUvLVfk3WLr7V/HzMmXFrur0gZ7MXLpVAOuUC6+fpsTenc4as46ZiOG29wtkhtMDT7 VPEssqbCB90/qeZcZ9Chkv91DSGZGxcVEoHfiE0rgdPlIAjZPrGM+HlbePm47a2Zyg0M 9nr57bvVuI+bCFLAt4Wfu6j9P88peFf2pqzAVaLhkQVsCgHb6L1GhSD4el+yIAh/E0FH zATv0hTttVYGkWEPJm4Mmy+wRe0q1lDgcq4nXHDbARqhI8ULZr4yj+l97B1O9ved0/jU yTVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c69GUb5e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s15si10809996pgj.350.2019.06.05.08.01.28; Wed, 05 Jun 2019 08:01:47 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c69GUb5e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728535AbfFEO6c (ORCPT + 99 others); Wed, 5 Jun 2019 10:58:32 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54605 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728448AbfFEO6c (ORCPT ); Wed, 5 Jun 2019 10:58:32 -0400 Received: by mail-wm1-f65.google.com with SMTP id g135so2591193wme.4 for ; Wed, 05 Jun 2019 07:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=JMXXe6AqnjayglXVoDkqd6XGPAOEachog6ijJh1WH/M=; b=c69GUb5e0zImhjjK5JB+615hWzoFJvTWr+iOyLMJviK5KxLRr6jgx4UWBf5OZDtr5O ULDsZSGivOv11ZfUEV2OsGG9u3/8QETHCb2Ot9NobhSlJtJFqaIUbZhvKqerxqPsf4dv AFV1ijerqAf4dvnIKNg1r/kW2g1/JmNJbdH7hZRndW1J1WB89VlxAIKj+iVTUBOpyvli ZZjKkqgU9LLz8VDcrqr+w10FnSDY4Y0NnQJ/1YUArGkPzxKo8Sc2ToqtEHlHdzCwTBYI eM6KcvHjoI7SK/jyBVSUyHIPMHcjBLp3SOUa2uFBvk1AI4tYhw+gM1c8UL665/Brj68w gRXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=JMXXe6AqnjayglXVoDkqd6XGPAOEachog6ijJh1WH/M=; b=TScFG2IIv13+LrkNgEZifgKdCKEWTGKB4R7SdvaKx69oKTPKoAOJjIZtnHMh7wNL92 1HdIVsLH9ChHksbE43XrZHlRNlyNVkw5HqSI/VxB0m8TD8O09kdhAVHry5InjNBQEF9z 2i7VZHU1nsiZf37SsVRzUZoCWl8G7DBKFVYQOLgAs0LQa0xSsjpE3dsDshfpMFit/cLo wzL7uz3AOfARCaBcr6m34m5tYFlDDiG6yKzcswyKbpFzRPzBw2eo0v47jHtf/tJzu9G2 pPFY2oEAAl/FlfZoH2nSRdmIVSW08/vqK6EuqHByB4QHTH6quBAKrzhuCXnrPaReZ9Hx yM4w== X-Gm-Message-State: APjAAAUkH/jgYp6o6zhSRJyy0BUcrVUKH0hNhIzW3npC0kZ31Z/PyqAf ZpAwPYSD7P9yf4t+SizV7rxej9Up X-Received: by 2002:a1c:6154:: with SMTP id v81mr22169029wmb.92.1559746710125; Wed, 05 Jun 2019 07:58:30 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id 34sm28309312wre.32.2019.06.05.07.58.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 07:58:29 -0700 (PDT) Date: Wed, 5 Jun 2019 22:58:20 +0800 From: Gen Zhang To: Mike Snitzer Cc: Jiri Slaby , agk@redhat.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: Re: dm-region-hash: Fix a missing-check bug in __rh_alloc() Message-ID: <20190605145820.GA3465@zhanggen-UX430UQ> References: <20190524031248.GA6295@zhanggen-UX430UQ> <79ec221d-6970-3b30-0660-4a288a4c465e@suse.cz> <20190605122159.GA32538@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190605122159.GA32538@redhat.com> 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 On Wed, Jun 05, 2019 at 08:21:59AM -0400, Mike Snitzer wrote: > On Wed, Jun 05 2019 at 2:05am -0400, > Jiri Slaby wrote: > > > On 24. 05. 19, 5:12, Gen Zhang wrote: > > > In function __rh_alloc(), the pointer nreg is allocated a memory space > > > via kmalloc(). And it is used in the following codes. However, when > > > there is a memory allocation error, kmalloc() fails. Thus null pointer > > > dereference may happen. And it will cause the kernel to crash. Therefore, > > > we should check the return value and handle the error. > > > Further, in __rh_find(), we should also check the return value and > > > handle the error. > > > > > > Signed-off-by: Gen Zhang > > > > > > --- > > > diff --git a/drivers/md/dm-region-hash.c b/drivers/md/dm-region-hash.c > > > index 1f76045..2fa1641 100644 > > > --- a/drivers/md/dm-region-hash.c > > > +++ b/drivers/md/dm-region-hash.c > > > @@ -290,8 +290,11 @@ static struct dm_region *__rh_alloc(struct dm_region_hash *rh, region_t region) > > > struct dm_region *reg, *nreg; > > > > > > nreg = mempool_alloc(&rh->region_pool, GFP_ATOMIC); > > > - if (unlikely(!nreg)) > > > + if (unlikely(!nreg)) { > > > nreg = kmalloc(sizeof(*nreg), GFP_NOIO | __GFP_NOFAIL); > > > + if (!nreg) > > > + return NULL; > > > > What's the purpose of checking NO_FAIL allocations? > > There isn't, that was already pointed out in a different thread for this > same patch (think patch was posted twice): > https://www.redhat.com/archives/dm-devel/2019-May/msg00124.html > > Mike Thanks for your reply. The first thread is not replied for a period, so the second one is posted. But I don't know why Jiri replied to the first thread. Thanks Gen