From patchwork Fri Aug 23 19:56:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 11112359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 992A713A4 for ; Fri, 23 Aug 2019 19:56:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7700122CE3 for ; Fri, 23 Aug 2019 19:56:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="XmdnQ3XP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387956AbfHWT4o (ORCPT ); Fri, 23 Aug 2019 15:56:44 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:46386 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387860AbfHWT4o (ORCPT ); Fri, 23 Aug 2019 15:56:44 -0400 Received: by mail-qk1-f195.google.com with SMTP id p13so9235537qkg.13 for ; Fri, 23 Aug 2019 12:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id; bh=vTaAshi9pluGjENrrfftMicTMpjOrhGopwZB6hzguXI=; b=XmdnQ3XPOSwrLu3tByxh+ZVBCu+8gf4v3QrEQR7MLi6j6hCE30XvsnJlLL3xDZlsdg V1QEtfzdpAf2+cNrL+4PWXQ1bkdi4NPtQUY21KiBJBxJjlLTYKtN1Ev401gmS8S9+QBa rrse08tR0y5CdeiPpQM5Lr6s/vZBeJS0OcSoV0Zcn+GSOtvQmMs4JWZz2HzJ5oNt6S0e SLjINAoTnzuj3cLyU+aKUhFN9ity7DDqvCICkoz9933SUyRY5JR1DTyKatCz8RQMw8Zr 8KoaRwTw14XZYst0RkajkIELjTnq6a7JkugjoJ37Y9ZCFdWmqih+POIn4bBq7NMGOT8Y o7OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vTaAshi9pluGjENrrfftMicTMpjOrhGopwZB6hzguXI=; b=sgRriGXrjnk63laXBehC0WWskMnDVh8f4oJJRBF7l69NLGUHlL5R/67+VfRNOQkxqL VdbLsr0zDGdL3QBcwWImUXx4+yVbjokTfK7k3bgSzxdH2Otb1xrJYazkQfRacyWCAYnX SXMThJWUPro5yF39DK8eqtKj6tKMEXlCk1QQh3FWrQYi5YCvW0l4BOTGH+8Ka9PvHRn6 uuTPNEsMxtaASlml5wUBOrINt5N0siIMmwf0EqVJXE6uQ2tRcxk5teoCvfLThIH6Xp+y iB/1obZh8gvXZQEqmy2Aw/+/NmvadY72YsKp+JM0B/j8jbzHHyEL+H673RB9LRBhXSl2 nR3w== X-Gm-Message-State: APjAAAXdcWgCs/7RG82CF/4Av7EgS59FQjDrMHmON5cvWWsPeJGZLv8t Fy3aYUL0R/V/RhhUpWrk3ZM+HA== X-Google-Smtp-Source: APXvYqxgf5wgeiL6ufbZ334VqWwMQGezy5CWWm0nzrMhCFpi0O8GIzGoB/gmIFkF6u6wtWR6LRzjFQ== X-Received: by 2002:a37:9c88:: with SMTP id f130mr5826483qke.494.1566590203704; Fri, 23 Aug 2019 12:56:43 -0700 (PDT) Received: from qcai.nay.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id n21sm2159771qtc.70.2019.08.23.12.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 12:56:42 -0700 (PDT) From: Qian Cai To: saeedm@mellanox.com Cc: leon@kernel.org, davem@davemloft.net, moshe@mellanox.com, ferasda@mellanox.com, eranbe@mellanox.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH] net/mlx5: fix a -Wstringop-truncation warning Date: Fri, 23 Aug 2019 15:56:23 -0400 Message-Id: <1566590183-9898-1-git-send-email-cai@lca.pw> X-Mailer: git-send-email 1.8.3.1 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org In file included from ./arch/powerpc/include/asm/paca.h:15, from ./arch/powerpc/include/asm/current.h:13, from ./include/linux/thread_info.h:21, from ./include/asm-generic/preempt.h:5, from ./arch/powerpc/include/generated/asm/preempt.h:1, from ./include/linux/preempt.h:78, from ./include/linux/spinlock.h:51, from ./include/linux/wait.h:9, from ./include/linux/completion.h:12, from ./include/linux/mlx5/driver.h:37, from drivers/net/ethernet/mellanox/mlx5/core/lib/eq.h:6, from drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c:33: In function 'strncpy', inlined from 'mlx5_fw_tracer_save_trace' at drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c:549:2, inlined from 'mlx5_tracer_print_trace' at drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c:574:2: ./include/linux/string.h:305:9: warning: '__builtin_strncpy' output may be truncated copying 256 bytes from a string of length 511 [-Wstringop-truncation] return __builtin_strncpy(p, q, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix it by using the new strscpy_pad() since the commit 458a3bf82df4 ("lib/string: Add strscpy_pad() function") which will always NUL-terminate the string, and avoid possibly leak data through the ring buffer where non-admin account might enable these events through perf. Fixes: fd1483fe1f9f ("net/mlx5: Add support for FW reporter dump") Signed-off-by: Qian Cai --- drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c b/drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c index 8a4930c8bf62..2011eaf15cc5 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c @@ -546,7 +546,7 @@ static void mlx5_fw_tracer_save_trace(struct mlx5_fw_tracer *tracer, trace_data->timestamp = timestamp; trace_data->lost = lost; trace_data->event_id = event_id; - strncpy(trace_data->msg, msg, TRACE_STR_MSG); + strscpy_pad(trace_data->msg, msg, TRACE_STR_MSG); tracer->st_arr.saved_traces_index = (tracer->st_arr.saved_traces_index + 1) & (SAVED_TRACES_NUM - 1);