Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4391554imm; Mon, 18 Jun 2018 14:14:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLC0WcCPYHTkyQLSg3fBK3DYkWpFRcC7e9GBOqUTZncK0VNnMqEJaxt5JyreeFOX0ncmk0E X-Received: by 2002:a63:24f:: with SMTP id 76-v6mr12587277pgc.252.1529356465568; Mon, 18 Jun 2018 14:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529356465; cv=none; d=google.com; s=arc-20160816; b=g0A8NN7tz3wDeV0HyhNqSMn+CfecST/Q5uBtXbNTznjl8SnsyL4AE2o9w/OacBcRRG kuWJI7TTOTeWJG4NFQfrM2OuEum2RydtqxUVdyzc1l7e87Rli2Qr89+qMPNGaSMXkqtH gspPX25SWUiPYEeHMvLeFE4cB1+86H9IkP90QP64vU5vGLXKXkNfJQ9cAD7QdX18a7aE 5z0RVEIu+2jHwZ5X1JqkkZqNc+sq3sy+GCuDQvf3Q8eRVI6ABI6k9xilFuTPdX4IHXVy Atxquknr+BGMraTqljo2mqT7BpgcCLbdjSJ1GhPMFN7pniH/8hYmAvJhxU1quPd/Hb+V lO4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=kCsOz5KSfsc8j59CUvbjtAkboo/JUxqvAXCGouVTbkM=; b=ixf1UhWDGwso4BeMQ9SXcz4wTRctq+OmNub6iUw8BLSx28M1uCLhwreBRhecQ9e5AW fL13JH7abbKXBtfgSRZpxQftrPkqxzF2GIWx8rbIpGwFJ4TP/O/gIZONEw5nveXeb8ZH SBcf/bOkZXcKCWg01qrjCOb7YWYGsDDqthNdrv9+vLD5oG6XdP6SR208W0s+BkVrI+v4 JF8GWqUerhWBcdL8AVkb1JfT6B/MXJtnvjjHGuEhc38tXOvkf9fyRwuS9f1qOvphJKtX o0gIEkFtfVElcmOrJrV4JGBvQmdP9d5tXZpGJevbKGQaWD0vPhruiAD4zp48OReDOwss c5mA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n7-v6si12676154pgp.434.2018.06.18.14.13.59; Mon, 18 Jun 2018 14:14:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936857AbeFRVMy (ORCPT + 99 others); Mon, 18 Jun 2018 17:12:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34040 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935854AbeFRVMy (ORCPT ); Mon, 18 Jun 2018 17:12:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FBA981663D5; Mon, 18 Jun 2018 21:12:53 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57E332156880; Mon, 18 Jun 2018 21:12:53 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id w5ILCr8w016278; Mon, 18 Jun 2018 17:12:53 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w5ILCra6016274; Mon, 18 Jun 2018 17:12:53 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Mon, 18 Jun 2018 17:12:53 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Kees Cook cc: linux-kernel@vger.kernel.org, dm-devel@redhat.com, Dan Williams , Mike Snitzer , Alasdair Kergon Subject: Re: [PATCH] dm: writecache: Use 2-factor allocator arguments In-Reply-To: <20180618175033.GA2627@beast> Message-ID: References: <20180618175033.GA2627@beast> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 18 Jun 2018 21:12:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 18 Jun 2018 21:12:53 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mpatocka@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 18 Jun 2018, Kees Cook wrote: > This adjusts the allocator calls to use the 2-factor argument style, as > already done treewide for better defense against allocator overflows. > Additionally adjusts style nit to avoid assignments in test expressions. > > Signed-off-by: Kees Cook > --- > drivers/md/dm-writecache.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c > index 5961c7794ef3..7773f4c75701 100644 > --- a/drivers/md/dm-writecache.c > +++ b/drivers/md/dm-writecache.c > @@ -259,7 +259,7 @@ static int persistent_memory_claim(struct dm_writecache *wc) > if (da != p) { > long i; > wc->memory_map = NULL; > - pages = kvmalloc(p * sizeof(struct page *), GFP_KERNEL); > + pages = kvmalloc_array(p, sizeof(struct page *), GFP_KERNEL); > if (!pages) { > r = -ENOMEM; > goto err2; > @@ -859,7 +859,8 @@ static int writecache_alloc_entries(struct dm_writecache *wc) > > if (wc->entries) > return 0; > - wc->entries = vmalloc(sizeof(struct wc_entry) * wc->n_blocks); > + wc->entries = vmalloc(array_size(sizeof(struct wc_entry), > + wc->n_blocks)); > if (!wc->entries) > return -ENOMEM; > for (b = 0; b < wc->n_blocks; b++) { > @@ -1480,10 +1481,13 @@ static void __writecache_writeback_pmem(struct dm_writecache *wc, struct writeba > bio_set_dev(&wb->bio, wc->dev->bdev); > wb->bio.bi_iter.bi_sector = read_original_sector(wc, e); > wb->page_offset = PAGE_SIZE; > - if (max_pages <= WB_LIST_INLINE || > - unlikely(!(wb->wc_list = kmalloc(max_pages * sizeof(struct wc_entry *), > - GFP_NOIO | __GFP_NORETRY | > - __GFP_NOMEMALLOC | __GFP_NOWARN)))) { > + if (max_pages > WB_LIST_INLINE) > + wb->wc_list = kmalloc_array(max_pages, > + sizeof(struct wc_entry *), > + GFP_NOIO | __GFP_NORETRY | > + __GFP_NOMEMALLOC | > + __GFP_NOWARN); > + if (max_pages <= WB_LIST_INLINE || !wb->wc_list) { The rest of patch is OK - but you shouldn't duplicate the comparison against WB_LIST_INLINE. Mikulas > wb->wc_list = wb->wc_list_inline; > max_pages = WB_LIST_INLINE; > } > -- > 2.17.0 > > > -- > Kees Cook > Pixel Security >