Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1296163rwi; Thu, 27 Oct 2022 13:58:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61KtKZIYh8q7LoTvR/i+RD/faWEtTHmptuGhQ6eAEQfSaPVm2u0jZJMj7rRwLcUMYK23Wz X-Received: by 2002:a17:907:7208:b0:78e:176e:e0c6 with SMTP id dr8-20020a170907720800b0078e176ee0c6mr43982605ejc.594.1666904336290; Thu, 27 Oct 2022 13:58:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666904336; cv=none; d=google.com; s=arc-20160816; b=h2WMtCJkRqNS3BFFDRG2B/5dl7Q/ULFyMRGtzW4jU1pkgC5rCwIzmOVL/8bOJ2a2eD 9dguQ4CSCxbrJUW9VolkRMrwUASV3Q4YKVeeS+b9vKjMtZvqcKBkj7KsI7u3MrqTB1xw zBtKCMfL8X/PKv97dmyVeuRjh5dT9iAcaIcd8XrVutWOYAf4ADPuGz/uArK6z3taapZv aYbkXMTYqm87BzyLyhVJvq6ayd5cfx2FrWLMKGretPOQQdIgUx3VdGfF4jWxNxUeidkV vAcBKWA6xupFhFy7AkB29ULm6TNaChTlUnp5VhJHVCF682r59kAfF8v8cJACE4B7OHvW hU5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=q7qkzsPf4Wsy3Ys2sVKTyt+Eo/JlciSvXArZDH9fmiY=; b=soYwc34QFnaE6c6Kx7wEcDkZptPx8WGfT9rVJo4eqMwgGgFgU6EAzRYhZDTYiDTcDf tGVbKAZRUGcwtK8J8HLQ1t9BZqbbQJw+/qKJcligxbZxaM7DOpo+oKLXADBDeoaulaQd LvL4f/ME8+UL92sHZZhQvdlDhFU/+rW8QZin4NVqG6/13uGHv0JJvVymBm9+0UhEydT1 RXve0pEkmG7nU1pyPF7l7cCCEg/wZBRjwwDeoIf6UmbXjOSDgzhJvCz/w1Ni6H39Thu/ ThnCfcE4o4rnTArs0EmtHTPV80fMmgS0AQU+mYW6ir6A5NAelGLwl6LygoIlcGVnDSyq EwMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l5gaCDVV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs39-20020a1709072d2700b00791a84056d9si2791209ejc.751.2022.10.27.13.58.30; Thu, 27 Oct 2022 13:58:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l5gaCDVV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236881AbiJ0UKQ (ORCPT + 99 others); Thu, 27 Oct 2022 16:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236819AbiJ0UKM (ORCPT ); Thu, 27 Oct 2022 16:10:12 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 609132CC9D; Thu, 27 Oct 2022 13:10:11 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id sc25so7796532ejc.12; Thu, 27 Oct 2022 13:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=q7qkzsPf4Wsy3Ys2sVKTyt+Eo/JlciSvXArZDH9fmiY=; b=l5gaCDVVhGQ8Y5EquY6I9Ojcw/dlIjSsABW1ecEFamptjjW1cnav6ZSYH/ssMqYhWv 8U8+rS9UiOElwdoXBq7KsG/SJjl8f+d8dm4xqnMGE/Ynda08atIgTGlQltUIh0oirbN8 /XaQkWc6PrcPeSELQyQI3cEOseDU2kR2rPpMM/bKOGeyXVroRwfrNZqJMAtOOHLB5RAd YLZoao0V0CAVDpZVthi/e+udKyu7ABs7AAFQB8lRpefedXFSfA2MxFB9TlweOEQJbYVp Hz7jXwbUzorSi1x9gqoaO/VZieBlWSlsgaWKwdEojYHzY2RCZBqU1hm86+0nj8/j3zbz gS5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q7qkzsPf4Wsy3Ys2sVKTyt+Eo/JlciSvXArZDH9fmiY=; b=qsD8Cd6Uh4tQoO0zfi2AL/MgxCsIqn4C7bFDBHHviKkprczbOMc2NfCQntl66VB1dX 1Nw/e6vTAjxTIreW3YkJtlFvrxNBgaonrhvdmo+KqUl+BUeXGBvZOATXX/H6fDyOtDlB XS1cKCW8BjsH4zTn+pnu4auqk6dZHMXs5YUOIz/uXKW/lT5w5OhN3TLvGEx+HpsoAOVd yP2GGMG0qAUiNKbV9nihtXhC1y/sKlfCodUMJ71RJ3qWuJgVLB966Sfwy3tE0EwDTkyy 1lb120eUjO31midfyfaL5oz9RmfdgjYXAYt4z1d2hvasBnkscIYQBwb7m3vDVCvB53W2 BJCQ== X-Gm-Message-State: ACrzQf2ymaKt2B1i8rul0enc0sB2fGwaCRogxC4LSG+sDfHNkSNGiPj7 4S2U8IGddyno24PtHwkGOx9VjGeO0F3YiSfQnIs= X-Received: by 2002:a17:907:2d91:b0:78d:8747:71b4 with SMTP id gt17-20020a1709072d9100b0078d874771b4mr43697599ejc.545.1666901409929; Thu, 27 Oct 2022 13:10:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Thu, 27 Oct 2022 13:09:57 -0700 Message-ID: Subject: Re: [PATCH bpf-next] selftests/bpf: Fix strncpy() fortify warning To: Rong Tao Cc: Rong Tao , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , "open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)" , "open list:KERNEL SELFTEST FRAMEWORK" , open list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 27, 2022 at 4:34 AM Rong Tao wrote: > > From: Rong Tao > > Compile samples/bpf, error: > $ cd samples/bpf > $ make > ... > In function =E2=80=98__enable_controllers=E2=80=99: > samples/bpf/../../tools/testing/selftests/bpf/cgroup_helpers.c:80:17: war= ning: =E2=80=98strncpy=E2=80=99 specified bound 4097 equals destination siz= e [-Wstringop-truncation] > 80 | strncpy(enable, controllers, sizeof(enable)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Signed-off-by: Rong Tao > --- > tools/testing/selftests/bpf/cgroup_helpers.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing= /selftests/bpf/cgroup_helpers.c > index e914cc45b766..a70e873b267e 100644 > --- a/tools/testing/selftests/bpf/cgroup_helpers.c > +++ b/tools/testing/selftests/bpf/cgroup_helpers.c > @@ -77,7 +77,7 @@ static int __enable_controllers(const char *cgroup_path= , const char *controllers > enable[len] =3D 0; > close(fd); > } else { > - strncpy(enable, controllers, sizeof(enable)); > + strncpy(enable, controllers, sizeof(enable) - 1); enable is not initialized, so we might end up with non-zero-terminated string. Let's enable[0] =3D '\0'; at the beginning and then strncat() here? > } > > snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_= path); > -- > 2.31.1 >