Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1946395ybv; Fri, 14 Feb 2020 08:40:45 -0800 (PST) X-Google-Smtp-Source: APXvYqx2wPXYSgsrDL0mFkwPxlekflrPejKa1LDD+/6SGNklP+dK94ljKbnAItB7thjUYD546aco X-Received: by 2002:aca:fd94:: with SMTP id b142mr2409700oii.11.1581698445281; Fri, 14 Feb 2020 08:40:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698445; cv=none; d=google.com; s=arc-20160816; b=BJY4tJB+7352Sww8vvIcqhxKGaIWDFaMvTxuFxB+tOScfHS80a6uxQCN9iN2o05Ymd Uw1fg0iWWMX9CTSpeCoxw3ObEEEcP4p0wmbdciwlzoXhzrZoZRtb8I+cP9Lf5O3C8wzG 2pDBKisDenSu/F9JpLAQuEzPzacx8aayeNzqP7ayygCwjIrQfZ/nfXf+bQV9SEUHO9Qj pOM9Yvb4Rpu1lbOiy+IUB6jgA25cGB0ni8Ssp/sOm0/GtqtR26yvPdyGaTE9elDfcvJX gMJUdnn6D+Umbx+0YoNluD2r9zOF4GCfMSY3KWJntGiXACtS/iuvKF9q7dEyMLgiJU1x SCMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LbTJOvZQSfaGf9zyy/Zrw0nFZqrVst+KMkiKa/H6VLo=; b=H7sNVuKrRv75FlYsr7B/LXdhkDTyOGQfbMC4TooErbz7wO/h8L0ZaGygSw0HcEvSEO rhUneZLzKLpLPTd/B/CaHNjl8m1SxakNzOpnAoy7OPuJLS0/GX7A1IE0a4g/XDMbkW0u cIU1sywrgb5skz0JLdse9SkSslw9HUHNuXEcbEMuQoxQpzhS26yOni6ldAQsDDMSDmJr v3tX6/GwQ11FffpVJu0boLuXFG0Wtzts9/fU1sv0Jcldr1lGfN/utR+8WqcBJXP6R1zo VEqSQZ6rC+C+ljWdauDLeW1Eib5INZFa3rjyM7mfNEobSrgBHdJ2VRPSIpH+DYzJ/n// AS+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mdMWciMj; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c18si4335897ots.317.2020.02.14.08.40.32; Fri, 14 Feb 2020 08:40:45 -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=mdMWciMj; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405761AbgBNQj4 (ORCPT + 99 others); Fri, 14 Feb 2020 11:39:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:59042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393326AbgBNQXD (ORCPT ); Fri, 14 Feb 2020 11:23:03 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 740FD24768; Fri, 14 Feb 2020 16:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697383; bh=Ba+QKGRskXBXvu0aL2I2KaAkS6/2ikohdEhv5jDvwgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mdMWciMj8iEskCf6Mmp0ynORluFwvLHnDay/UvheAkUrU+7ov7CJUzG8oYF34kdOb 64pOVdLKgxEBXYugCyzbGWJf/xvp/clNbvlDLw0+Bh50jgTQxIsJBNP0Vu/q+Ej3p9 hbhblqppxlS8EtwmrugQ3W431xlc3fr6PfkJqcCM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrey Zhizhikin , 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 AUTOSEL 4.9 079/141] tools lib api fs: Fix gcc9 stringop-truncation compilation error Date: Fri, 14 Feb 2020 11:20:19 -0500 Message-Id: <20200214162122.19794-79-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 f99f49e4a31e6..21e714cf0126c 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -194,6 +194,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"); @@ -203,7 +204,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