Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1616784ybv; Fri, 21 Feb 2020 00:21:42 -0800 (PST) X-Google-Smtp-Source: APXvYqxhb2OKzPyzZ2bSQ/tEvhyA0JcnzkWxwn7O2XGKTfIjofOLIQo86CBTKmquM2L0+99VR+Iz X-Received: by 2002:a9d:6e8f:: with SMTP id a15mr26435810otr.178.1582273302544; Fri, 21 Feb 2020 00:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273302; cv=none; d=google.com; s=arc-20160816; b=ipBG5n5SoJ6JaSrhNcJ8tGWCknLZYnOS0W6ddxSAu7FwtTwo/HhG9/hMFtizrXUeCV y5eB9rJuKbn2apah/vRJoyi8BPFU+kaiV64mb1v+tymXj3iXinFnrUsuYtBysk3fHSo+ QlBhIdIfsieK4sGxtjnQqz6tMBGmsFr0PTuRn88EzmXvsmYVBnb6EUqAoY/jwHMFF4VR SA22Kb8rB3Jo3HPaNKZ02wmmcnVK7cHm93ZsWiUC/XK6USvGPYXS7lmUPQEV71pgHAst Rv6QfZqFT07wKBYWtPwT/YlugG69fjvxwiFtNSV5L+QU7NUh08uHl2YlgwAXPAito1dZ nnmQ== 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=KEnADlgzTFhqvt+uhwI3phxWQBhY995WcOlrVd7URjE=; b=oxcnyqs/40rTa5qpk880k2CZdpw7aPcy9f/zkj9CMZ9Z/6/g44dTnQC74usgSvha2M DwVOVZT2C23nKmrBOYTHAQsZ9n3ysdSzYTrgi9Tc727y2cGJMyFTmwnvH7pq4Tchn03z 8/PZqlznN+/UKAZkWDHTZQbFgI0zR35PG1acAZrgFWrKqFnphkM/wDh+0Ayx45CspiF8 0SReStKBAfCaPrptzegWvlxwS14Y/Wg2M8fzySZZ7hYqLQP9JTvFmi+7PnzxJKqBJYaD DU7SpE9n2jZD5ynemw2+tC3QsVdP2k1sSnsStiSJpZk7jiGcgiE0R+zGTdp+80fHldc0 BNrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vdErMCkW; 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 c130si463119oib.182.2020.02.21.00.21.30; Fri, 21 Feb 2020 00:21:42 -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=vdErMCkW; 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 S2388187AbgBUIUs (ORCPT + 99 others); Fri, 21 Feb 2020 03:20:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:59838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388171AbgBUIUk (ORCPT ); Fri, 21 Feb 2020 03:20:40 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 60B3224697; Fri, 21 Feb 2020 08:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273239; bh=+PkrT4iG1T7Rl6JWmdEM27E+WQtpZRSY2P7dpNAA9Wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vdErMCkWx6jd9nwhNWY4pG0Bkr4GJtSTye19seYd0BlJ44CHGDDvlCytzMR27onLz oAKXjllKGLsjPqDDWZgk2LEKWEnKx1d5Q0V/ziWPbwWmJdWSMiBEODBtdVBQbRDvXd 59xk3t3wvPsnRp5d2SMLWaOFXgloZT0ZbcerDr4I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Zhizhikin , Petr Mladek , Jiri Olsa , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Kefeng Wang , Martin KaFai Lau , Sergey Senozhatsky , Song Liu , Yonghong Song , bpf@vger.kernel.org, netdev@vger.kernel.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.19 098/191] tools lib api fs: Fix gcc9 stringop-truncation compilation error Date: Fri, 21 Feb 2020 08:41:11 +0100 Message-Id: <20200221072302.916269809@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Andrey Zhizhikin [ Upstream commit 6794200fa3c9c3e6759dae099145f23e4310f4f7 ] GCC9 introduced string hardening mechanisms, which exhibits the error during fs api compilation: error: '__builtin_strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation] This comes when the length of copy passed to strncpy is is equal to destination size, which could potentially lead to buffer overflow. There is a need to mitigate this potential issue by limiting the size of destination by 1 and explicitly terminate the destination with NULL. Signed-off-by: Andrey Zhizhikin Reviewed-by: Petr Mladek Acked-by: Jiri Olsa Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Daniel Borkmann Cc: Kefeng Wang Cc: Martin KaFai Lau Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Song Liu Cc: Yonghong Song Cc: bpf@vger.kernel.org Cc: netdev@vger.kernel.org Link: http://lore.kernel.org/lkml/20191211080109.18765-1-andrey.zhizhikin@leica-geosystems.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/lib/api/fs/fs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index 7aba8243a0e7c..bd021a0eeef8c 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -210,6 +210,7 @@ static bool fs__env_override(struct fs *fs) size_t name_len = strlen(fs->name); /* name + "_PATH" + '\0' */ char upper_name[name_len + 5 + 1]; + memcpy(upper_name, fs->name, name_len); mem_toupper(upper_name, name_len); strcpy(&upper_name[name_len], "_PATH"); @@ -219,7 +220,8 @@ static bool fs__env_override(struct fs *fs) return false; fs->found = true; - strncpy(fs->path, override_path, sizeof(fs->path)); + strncpy(fs->path, override_path, sizeof(fs->path) - 1); + fs->path[sizeof(fs->path) - 1] = '\0'; return true; } -- 2.20.1