Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5943934ybi; Wed, 12 Jun 2019 11:07:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+LaE/XaqK1o623mYUe+mwa0oHvJMhYgU0tpu5vkC7Kg5q9PcUyi+LySaKrYrjad1qBo5z X-Received: by 2002:a65:5c88:: with SMTP id a8mr25758798pgt.388.1560362873409; Wed, 12 Jun 2019 11:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560362873; cv=none; d=google.com; s=arc-20160816; b=OCmjATjXWe6CbEsJGANg/PHu7yfDUiLmRo3D8lmCkkYBRSwbsBxxqqnYste1PtCgVd V/1sZ10ofGEjgLGgHS9PoZxmbC26fiG76dhuHKhbp6DLKparz4jbQyNevnE8lxqWbXLr dC5pPhpUFYA2B8spkymC7thqKtqd/QHi+LZAStk4EuFZsbv5b196vzB4/HZx/kJ/Wr7V 5v04UIhLf7xdSNSkmf/FipRkCqy1IlEJOuPVpTOeEC6NcwsK+xQagR4rib5eD4hDeovy zR3CVSO1TOAsw+fFH+8ksexmiPbgbtB5F6fEtoB2I92gkVZlObI/D2o61pqf7e5NPYik t3fg== 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:mime-version :message-id:date:subject:cc:to:from; bh=ojPCucGuNvUIJJsxBrQIxt6bcXSywPHmPqytZ9u9k58=; b=Th8EF/PVn5c9uZ5bplSLbh+8JtPTqfoDggC1B+3MrcEW2ZyFqqmzx1Nyt2yjJe3Y+d OCOVeZdNmB8rTLuMSrGsNwOIdd3dZ4Q9BdIbxE3VQ4mvMGG442LObpk+22VsXLMzl6YJ xF5azG5N3yaKZWUHowbDT/bQAamK7r85K5uwqAZE4beF05b3dhcvMeIfhbV2oUdcX330 YsnYO7rYV/A/H5vIgV5yrQ8JgrJFJdMXlpeHbbRRI028XGzEB39aYpc52En++toVUNSx qaExCuBAP1hK2ZDH9iSzDFX1Ni79Vo+l5GBMSR+UlBGcmRFv/CALllvoiQi28yprdlKR f+CA== 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 n1si311634pld.366.2019.06.12.11.07.38; Wed, 12 Jun 2019 11:07:53 -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 S2438123AbfFLQWe (ORCPT + 99 others); Wed, 12 Jun 2019 12:22:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48178 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406284AbfFLQWe (ORCPT ); Wed, 12 Jun 2019 12:22:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6AC530C0DD6 for ; Wed, 12 Jun 2019 16:22:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.17.52]) by smtp.corp.redhat.com (Postfix) with SMTP id 8D952600CC; Wed, 12 Jun 2019 16:22:27 +0000 (UTC) Received: by localhost.localdomain (sSMTP sendmail emulation); Wed, 12 Jun 2019 18:22:26 +0200 From: "Jerome Marchand" To: Alasdair Kergon , Mike Snitzer Cc: dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH] dm table: don't copy from a null pointer in realloc_argv Date: Wed, 12 Jun 2019 18:22:26 +0200 Message-Id: <20190612162226.18536-1-jmarchan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Jun 2019 16:22:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the first call to realloc_argv() in dm_split_args(), old_argv is NULL and size is zero. Then memcpy is called, with the NULL old_argv as the source argument and a zero size argument. AFAIK, this is undefined behavior and generates the following warning when compiled with UBSAN on ppc64le: In file included from ./arch/powerpc/include/asm/paca.h:19, from ./arch/powerpc/include/asm/current.h:16, from ./include/linux/sched.h:12, from ./include/linux/kthread.h:6, from drivers/md/dm-core.h:12, from drivers/md/dm-table.c:8: In function 'memcpy', inlined from 'realloc_argv' at drivers/md/dm-table.c:565:3, inlined from 'dm_split_args' at drivers/md/dm-table.c:588:9: ./include/linux/string.h:345:9: error: argument 2 null where non-null expected [-Werror=nonnull] return __builtin_memcpy(p, q, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/md/dm-table.c: In function 'dm_split_args': ./include/linux/string.h:345:9: note: in a call to built-in function '__builtin_memcpy' Signed-off-by: Jerome Marchand --- drivers/md/dm-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 350cf0451456..ec8b27e20de3 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -561,7 +561,7 @@ static char **realloc_argv(unsigned *size, char **old_argv) gfp = GFP_NOIO; } argv = kmalloc_array(new_size, sizeof(*argv), gfp); - if (argv) { + if (argv && old_argv) { memcpy(argv, old_argv, *size * sizeof(*argv)); *size = new_size; } -- 2.20.1