Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1636856rwb; Sat, 19 Nov 2022 00:17:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5jXGtdHJGYqlmXxBWS9gHHtyY1rXA/ucoNAxe3pF3DPMoKpiNOLq6kGK6Zu63XwFFQsry4 X-Received: by 2002:a05:6402:1107:b0:463:9b53:cbf6 with SMTP id u7-20020a056402110700b004639b53cbf6mr648940edv.173.1668845839174; Sat, 19 Nov 2022 00:17:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668845839; cv=none; d=google.com; s=arc-20160816; b=Z1BYzY9hm+tHiG7bFXSc3MiADJX+hIhis+BnF9tHH+RV8LtLPlB/1FqK2ByGzkCBeJ XWFEpCuQsVyBij9rz1IXfvFiV/Hsnyoz6rfyFuSghxXA7RYFkvPgTCbzf0LBc1u3hCG7 Q6+/lrGWQfsjyMdEtt4KUe3U0HztSiRQ7sB+dCRRc34vyQs70MiKs7/1QygEGIdfvpod xuR8tU++tGYxcKwPO7QVCCVH13obuM2tNIC6BYpaB3vRk+tgEcinOna9EnOuLuc/F/Vm YOlx2JrNPyNaKu9LjAscPU9XoLKC+Trn4KD3ok/vM0AOaRr0wq52GPYVUf0x6WmqpRNO +niw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LvMoe8VUA5uhz3OEQIWJqcyeWyUyKp88MRRRVcKi5+g=; b=BHupCchCvqGraKr1zGOn4O9g78ClMVrZvn/6bKQQ2CmKU1ujmdn8vVeO2BXwFNx1Wz JzJHeMUraKgi+skgwgEQpVqhkKnxCjHHsMYJHU0rB3cll+867svx0LY4XIclfTAuMnPp vmorg1w0+T36fceN9qoSE3MDUMQkX6wwGpUKHYjbzcQxy4xZMT3Y5Ji0PYzOupYbv571 xs2jeUWyeg3UseHFm8Gr8WOgE/sYJawBHJOKzsTxTBFaOmbEl1bgxJsI0PICe53jS41U RbIJXSmw4OTk9bZ+2IBomlMDb8vs+ENR8MVMQjks2EnOBV3uTIqBGJWRxnLF6xE82Ec6 ALUg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw5-20020a170906478500b007adcc8fb7a0si5346557ejc.399.2022.11.19.00.16.57; Sat, 19 Nov 2022 00:17:19 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbiKSIOf (ORCPT + 90 others); Sat, 19 Nov 2022 03:14:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbiKSIOU (ORCPT ); Sat, 19 Nov 2022 03:14:20 -0500 Received: from gw.red-soft.ru (red-soft.ru [188.246.186.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F11CEB1EE; Sat, 19 Nov 2022 00:14:17 -0800 (PST) Received: from localhost.biz (unknown [10.81.81.211]) by gw.red-soft.ru (Postfix) with ESMTPA id 6CC043E1870; Sat, 19 Nov 2022 11:14:15 +0300 (MSK) From: Artem Chernyshev To: Chris Mason , David Sterba Cc: Artem Chernyshev , Josef Bacik , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2] btrfs: rcu_string: Replace strncpy() with strscpy() Date: Sat, 19 Nov 2022 11:13:29 +0300 Message-Id: <20221119081329.2213244-1-artem.chernyshev@red-soft.ru> X-Mailer: git-send-email 2.30.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 173646 [Nov 18 2022] X-KLMS-AntiSpam-Version: 5.9.59.0 X-KLMS-AntiSpam-Envelope-From: artem.chernyshev@red-soft.ru X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Auth: dkim=none X-KLMS-AntiSpam-Info: LuaCore: 502 502 69dee8ef46717dd3cb3eeb129cb7cc8dab9e30f6, {Tracking_from_domain_doesnt_match_to}, 127.0.0.199:7.1.2;red-soft.ru:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;localhost.biz:7.1.1 X-MS-Exchange-Organization-SCL: -1 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, bases: 2022/11/19 06:27:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2022/11/19 04:59:00 #20584775 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Using strncpy() on NUL-terminated strings are deprecated. To avoid possible forming of non-terminated string strscpy() could be used. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 606686eeac45 ("Btrfs: use rcu to protect device->name") Signed-off-by: Artem Chernyshev --- V1->V2 Fixed typo in subject fs/btrfs/rcu-string.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/rcu-string.h b/fs/btrfs/rcu-string.h index 5c1a617eb25d..d9894da7a05a 100644 --- a/fs/btrfs/rcu-string.h +++ b/fs/btrfs/rcu-string.h @@ -18,7 +18,10 @@ static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask) (len * sizeof(char)), mask); if (!ret) return ret; - strncpy(ret->str, src, len); + if (WARN_ON(strscpy(ret->str, src, len) < 0)) { + kfree(ret); + return NULL; + } return ret; } -- 2.30.3