From patchwork Tue Oct 18 15:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1691582 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=tXLmW8o7; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MsHT240rDz23jx for ; Wed, 19 Oct 2022 02:14:14 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1okoIB-0000pp-St; Tue, 18 Oct 2022 15:14:07 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1okoI9-0000oy-2j for kernel-team@lists.ubuntu.com; Tue, 18 Oct 2022 15:14:05 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C39A53F535 for ; Tue, 18 Oct 2022 15:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1666106044; bh=M97G+cvLMA9KLKvKHsGcFWSyFq+4i7x9mYI8YlJC+z8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=tXLmW8o7ssxz5aWetkyXZ88uPYQ1+grFku36rODEy0fnDpTcNnr7rs9YaAarP2gO8 e6gxErimt4rZFjsL3C1CQTri9ExYgadS6KtdryNwlsHK9HPsTcQt3fXxpydQQ3oEd6 wJXGwlkJPLCYzKw366LmvW4XHavs9sLVc0eFl1jr9jvLPoAGvZZ532Zng1Z9y/m0cS OJrzDVoSgdfE/VaY/8gYiWX+p6GNVzAZJnSM/gWGDNw1o3VV7Tki/+PsMpWiI6v/Wd cdkXVGz8ADn82OCtHTEXf/+W0n8xmxUrBY9sjHtt9cJihp0B//eO0CidFL40h/w4mt ymlWQ2zztchJg== Received: by mail-pf1-f200.google.com with SMTP id s2-20020aa78282000000b00561ba8f77b4so7861071pfm.1 for ; Tue, 18 Oct 2022 08:14:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M97G+cvLMA9KLKvKHsGcFWSyFq+4i7x9mYI8YlJC+z8=; b=XLrCiBCfWGk+T961OIkhQfwxHoPWmZyz5n9EpxkyJahhsm2c/biIw7WQrXuI7+eicp affhtk4Yy4+VVua7J/D4cxBdGZZCgR2tmui5f9X5RrUXtAPwBzddHEludZ22zLWkpBjb 5XRYGeYcPibzs03+o5mcbs1AJ5I8NNOmJFvv+PwNbJqZ/lT7xpkPpE/0N1nakfQrFTj8 o9eO1alPhV8VYRYvWSfMNujaAwjvZUeea9uycKxcn3tZuzRStDNt1BA1xiXhrfFMS1xs an2G0g/M97etPXaqwKxgx1Oeqzbc8Lon4Ytux5gjZ+hgmx5SliTQiwrVE48ux8385Kog m4aw== X-Gm-Message-State: ACrzQf1nZlgnqgqYT9fYzBD7e6Xrz1MfSdEQn3lV5ANXcArTdOdl8is3 W0Afx6JZZBbI5hiXbjFk1ZenGre3B2ebMV1Aj9TBhIZOB06zHKrqJq98DFdLyviucbeSX5zXF1a +T85NX52fumec254OkNn1Eh/lDGYRAa0Dh3SYwjcTqA== X-Received: by 2002:a17:902:8e84:b0:178:57e4:805b with SMTP id bg4-20020a1709028e8400b0017857e4805bmr3454269plb.144.1666106041923; Tue, 18 Oct 2022 08:14:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7R91ptA/ppvVnrgUJ6FKBiRxXjM/gn/BGBJt7QQq14GfCagTkH36zoDChAWfun2I180YqqsQ== X-Received: by 2002:a17:902:8e84:b0:178:57e4:805b with SMTP id bg4-20020a1709028e8400b0017857e4805bmr3454152plb.144.1666106040402; Tue, 18 Oct 2022 08:14:00 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id w11-20020a170902ca0b00b0017f7fa6808csm8840019pld.87.2022.10.18.08.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 08:13:59 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH][jammy/focal linux] md: Replace snprintf with scnprintf Date: Tue, 18 Oct 2022 09:13:18 -0600 Message-Id: <20221018151318.167543-3-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221018151318.167543-1-tim.gardner@canonical.com> References: <20221018151318.167543-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Saurabh Sengar BugLink: https://bugs.launchpad.net/bugs/1993315 Current code produces a warning as shown below when total characters in the constituent block device names plus the slashes exceeds 200. snprintf() returns the number of characters generated from the given input, which could cause the expression “200 – len” to wrap around to a large positive number. Fix this by using scnprintf() instead, which returns the actual number of characters written into the buffer. [ 1513.267938] ------------[ cut here ]------------ [ 1513.267943] WARNING: CPU: 15 PID: 37247 at /lib/vsprintf.c:2509 vsnprintf+0x2c8/0x510 [ 1513.267944] Modules linked in: [ 1513.267969] CPU: 15 PID: 37247 Comm: mdadm Not tainted 5.4.0-1085-azure #90~18.04.1-Ubuntu [ 1513.267969] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 05/09/2022 [ 1513.267971] RIP: 0010:vsnprintf+0x2c8/0x510 <-snip-> [ 1513.267982] Call Trace: [ 1513.267986] snprintf+0x45/0x70 [ 1513.267990] ? disk_name+0x71/0xa0 [ 1513.267993] dump_zones+0x114/0x240 [raid0] [ 1513.267996] ? _cond_resched+0x19/0x40 [ 1513.267998] raid0_run+0x19e/0x270 [raid0] [ 1513.268000] md_run+0x5e0/0xc50 [ 1513.268003] ? security_capable+0x3f/0x60 [ 1513.268005] do_md_run+0x19/0x110 [ 1513.268006] md_ioctl+0x195e/0x1f90 [ 1513.268007] blkdev_ioctl+0x91f/0x9f0 [ 1513.268010] block_ioctl+0x3d/0x50 [ 1513.268012] do_vfs_ioctl+0xa9/0x640 [ 1513.268014] ? __fput+0x162/0x260 [ 1513.268016] ksys_ioctl+0x75/0x80 [ 1513.268017] __x64_sys_ioctl+0x1a/0x20 [ 1513.268019] do_syscall_64+0x5e/0x200 [ 1513.268021] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 766038846e875 ("md/raid0: replace printk() with pr_*()") Reviewed-by: Michael Kelley Acked-by: Guoqing Jiang Signed-off-by: Saurabh Sengar Signed-off-by: Song Liu (backported from commit 1727fd5015d8f93474148f94e34cda5aa6ad4a43) [rtg - context adjustment] Signed-off-by: Tim Gardner --- drivers/md/raid0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c index 1a2b9364e170..cc62f12900b2 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -48,7 +48,7 @@ static void dump_zones(struct mddev *mddev) int len = 0; for (k = 0; k < conf->strip_zone[j].nb_dev; k++) - len += snprintf(line+len, 200-len, "%s%s", k?"/":"", + len += scnprintf(line+len, 200-len, "%s%s", k?"/":"", bdevname(conf->devlist[j*raid_disks + k]->bdev, b)); pr_debug("md: zone%d=[%s]\n", j, line);