Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2654269imj; Mon, 11 Feb 2019 06:32:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IZfLXWASXV6horV2YkTaoofyJk+03OpMqQuRC89iJrvmSA0Te5qZxSldk6T/vxrl0UKt68u X-Received: by 2002:aa7:80d7:: with SMTP id a23mr36484297pfn.86.1549895521344; Mon, 11 Feb 2019 06:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895521; cv=none; d=google.com; s=arc-20160816; b=zUBA7X/pVypTc2oNGbE0QgJxzH1cy/QZarYCKlNcJnaw6UttrnUsl+rD1C6OvmUFWV oBuWV6U5ctSzEu7wLZ53wn12k4Ao/fmY8wCANX7BBaspXuaUurVIfniNebbA5zRhJHaf eOm6uqaEzZ089UVDzt49kd/e9QvLpv9N6L0/kmJl3Gb3rw5noGE58AnyX2FDjAsS9rtH DCkPP0xuFN21PD7fUvKjOAHMgg3k/GtRH94+VKyYkKaQeXeEKJA1LnUpvuEEs3C6H60b MNc8Qlb1g/nOBLU+KEGE/7LryMfo4xiFCXajHFWr890XOe+FN/+nCQADvhvxDc99hwHK vTRw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hm0yWPRPXxI5hS6AHBIrExdzBxijRVw9Ytk3Qb6dTEs=; b=Vfjdwh1jMlXbLTN+WKbkq2Gt94uYpqea3rBou+vvWFH0ARAHIbC5WuQ0M1tp1QLrxi 7PvBI8+vYzOsYd7egqjB1HaWHVnxciBJTxmJ5aRBOFcmMwhnRI8xZw6zXaRqyc/MXolK 3jz1/DxAELd5yRaR68W3jNSeL+vD8xQGPTZ3xEUQFMeT1nnStE6GSuy/uqy3i7UL1DBe uNYdOj3vmE8H5jwOBCiGLHGLmzw5f5rQ4HAwNH0uQFBSXxB0lAwOIb5wntQ/52yKsvHg WdPAAgpM+7okMB1oK4IlssQoIPzO5BqV5e9btwKzSd6yXzzLgwTg4t+yj0UOVY/Xc6QJ bfaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jV1v1/G2"; 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 v3si1959485pgr.191.2019.02.11.06.31.44; Mon, 11 Feb 2019 06:32:01 -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; dkim=pass header.i=@kernel.org header.s=default header.b="jV1v1/G2"; 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 S1729111AbfBKO34 (ORCPT + 99 others); Mon, 11 Feb 2019 09:29:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:35984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728415AbfBKO3v (ORCPT ); Mon, 11 Feb 2019 09:29:51 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 08D592075C; Mon, 11 Feb 2019 14:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895390; bh=yrp8uqFHK7uwYbqCqPdn7Kj+sSiWFpE9NqTQwqafvlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jV1v1/G22fLh591DrmPK05KLxP0ASmTZSREVfQSeGEZN2/ZUSjcjiUMTypH+zvssP OBdPN9En1LZfXhA4c9e5Y5ESS4X1Xmo5VioGfVT5iilYQNG/9s/SoNPM9a6PqKUgZ+ iVPviTyGLJgb4lHhJzMYWdwt3FmyrYfwkX/4T1Hg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.20 190/352] perf probe: Fix unchecked usage of strncpy() Date: Mon, 11 Feb 2019 15:16:57 +0100 Message-Id: <20190211141859.215511088@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit bef0b8970f27da5ca223e522a174d03e2587761d ] The strncpy() function may leave the destination string buffer unterminated, better use strlcpy() that we have a __weak fallback implementation for systems without it. In this case the 'target' buffer is coming from a list of build-ids that are expected to have a len of at most (SBUILD_ID_SIZE - 1) chars, so probably we're safe, but since we're using strncpy() here, use strlcpy() instead to provide the intended safety checking without the using the problematic strncpy() function. This fixes this warning on an Alpine Linux Edge system with gcc 8.2: util/probe-file.c: In function 'probe_cache__open.isra.5': util/probe-file.c:427:3: error: 'strncpy' specified bound 41 equals destination size [-Werror=stringop-truncation] strncpy(sbuildid, target, SBUILD_ID_SIZE); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Cc: Adrian Hunter Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Fixes: 1f3736c9c833 ("perf probe: Show all cached probes") Link: https://lkml.kernel.org/n/tip-l7n8ggc9kl38qtdlouke5yp5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/probe-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index aac7817d9e14..0b1195cad0e5 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -424,7 +424,7 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target, if (target && build_id_cache__cached(target)) { /* This is a cached buildid */ - strncpy(sbuildid, target, SBUILD_ID_SIZE); + strlcpy(sbuildid, target, SBUILD_ID_SIZE); dir_name = build_id_cache__linkname(sbuildid, NULL, 0); goto found; } -- 2.19.1