Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1528350lqe; Mon, 8 Apr 2024 11:26:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWoO7NZ3DPEVDfToKq/qo05hj6PghtPQIvhfWCwTkfGCw6u4H0cK/9IxrUfuIaRRcvGxmRw9aThOAZxPnsHuhZPXov3W27UjB4rQh9kwA== X-Google-Smtp-Source: AGHT+IHP7a/HPDT5G88gQ+h5uZkvKnpUgg0cxlsW1iRFcZXfKtrtSkvadsC7gqxP8PMHOn4qoo/D X-Received: by 2002:a05:6512:3d09:b0:513:c6ec:fa6c with SMTP id d9-20020a0565123d0900b00513c6ecfa6cmr8709012lfv.48.1712600794883; Mon, 08 Apr 2024 11:26:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712600794; cv=pass; d=google.com; s=arc-20160816; b=HLXIUwb7zezxirB80vIZV/gKoruqaNMZlMYo06eNhSvTqgifJoQr8+ioVHvUe8EbfC nRpacJOR3XWR5pzTn00zkcjtkEPs40awuoj4XcUJOo05dMpd44/l4qMC4CRtUz5dKqeW dfcFpTMq7rTEVsimCid9PmBE+QX5V8hobRaugoGv842yv3Q/m8k4nBU+KHB2RyCte1Iq idD8+LQK7fsAsdd46s4/BgVQmz+u92yZ0YaPUZ+L96lv+CDwjvyVYAlutGXH2z8v36pk fWn7SQIlWX2yTBjByjsO4zjdyRDhyVZ5wsxs55KInq8N6w/Dp1C7d90nixH4Roi2HizQ ZEvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:date:references:in-reply-to:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:feedback-id:dkim-signature; bh=/K3aQJmXOOnBZ/HZad9fE2sFcmGKHfWPzZd8B/WHGeY=; fh=a/CCv9s866nHy56CAI1caTHYMKG3CtTUayHGP0jwYrw=; b=Parr4N5mPUpQtAYnU9v33bh766oaO3f1gN4FzC/LGUvfSrUWfRbkm7nqYEY6/s6qai JuHycpgbySSmFFX3F6kmt7gQZcwil+RGDqUwK3MBS8f+kEV0Cpfbh5k9+G2Ok+8DTgfR 4EP4mS9Vty8aYfmEf2lEzo7DEXUuENJjufyU+5CE1/yHDy2o7po7Qe+A2MvuT1zl2eSX gVGgnWMuW5iOOw+YBmCaoXtWcR05nPcaLTebEexM4CTOWUlG5XSWT4SaqkPV24JoulCS +uDKyB+W2Zq8uEWj7uXBr254m7EDBruAKnEbL0fr/St3lMb5AQEUhyV87CvQs9ibzsBK M1vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Jgl/1v36"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135813-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135813-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id he39-20020a1709073da700b00a44d0209395si4012801ejc.915.2024.04.08.11.26.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 11:26:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135813-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Jgl/1v36"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135813-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135813-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 83F9E1F250DF for ; Mon, 8 Apr 2024 18:26:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 641A3144D3A; Mon, 8 Apr 2024 18:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jgl/1v36" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8190025753 for ; Mon, 8 Apr 2024 18:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712600782; cv=none; b=u4nbrKU/rKQxp8P5ZWw2VviYvRf+pOJVWdH5idCow6KV+MgEHL4UKHTJxCbtBmxJ2AifTBf/icRdL8Biwwc9tM9ey6XuQVc2o7q/PGHy3qzf0zhK8CS5GBKIRZhACVUJbGHtCD5xgXHLpwNE8wKsOBsl6eUcIPiXxcrCPSJfJfM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712600782; c=relaxed/simple; bh=zHVhbDUXvIHrWkiMCgJm6IIlq6tLgPd0bdBaL4AIw+g=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=GgqtS0wCJ7EBsaoM8kb+C3ObWmgmsmyohD5Mq4LNhLf0r8WPVNsdtPaRC6PG4B20WnCdwegNvqn5fWh7A+q4A+Qc1sbYotGSsN9SlHgi0cWmWEnVfwJPsIjQz5Eh+itEv6VZlt++Srcj0aPc9hJgpAqX3RilWYza+jVMFnRs5yw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jgl/1v36; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2073C433C7; Mon, 8 Apr 2024 18:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712600782; bh=zHVhbDUXvIHrWkiMCgJm6IIlq6tLgPd0bdBaL4AIw+g=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=Jgl/1v36x9gPDRGRtgHLpwSWPWCHyO0Au+aX1+oeGjrzJlGRsUOmUY1aLymZ1LD1l uriWZpqBeVIymR/WovDHQoyS0iLtOWMaZ9T6TX6ZZDnAdBr1VVPrskaCTEUMzChLFF b271khNSiAkAf9N/7A2kcLCykf4hAdXZSA5fMuGNmvAYNC1SC2tds+cnVaf3wcfzym 5upBRFtDc+qeB/F50U21OOXfzubYNKKNiLpLm+p2vsiyYnmoAG8gO70G+sU+R5kfTB jQK90zKMDPSbIeJ+HSqnJbN2hPnWoyW5CQliIRm23OG+D2MvYaf1UCg8kslhr37SsL RMbdKOukmcmZg== Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfauth.nyi.internal (Postfix) with ESMTP id C1C131200066; Mon, 8 Apr 2024 14:26:20 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Mon, 08 Apr 2024 14:26:20 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegiedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugeskhgvrhhnvghlrdhorhhgqeenucggtf frrghtthgvrhhnpefgffejleeluddugfejueeiteefvddtgfeutefhvdfgudfhveekgeeh gfevledvudenucffohhmrghinhepphgrshhtvggsihhnrdgtohhmnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghrnhguodhmvghsmhhtphgr uhhthhhpvghrshhonhgrlhhithihqdduvdekhedujedtvdegqddvkeejtddtvdeigedqrg hrnhgupeepkhgvrhhnvghlrdhorhhgsegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i36794607:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 81795B60089; Mon, 8 Apr 2024 14:26:20 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-368-gc733b1d8df-fm-20240402.001-gc733b1d8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <1622d9ff-feed-4a12-9d8d-3f00088c9edf@app.fastmail.com> In-Reply-To: <76214105-94ae-4540-8511-e9e2ff6d257e@moroto.mountain> References: <20240328140512.4148825-1-arnd@kernel.org> <20240328140512.4148825-11-arnd@kernel.org> <76214105-94ae-4540-8511-e9e2ff6d257e@moroto.mountain> Date: Mon, 08 Apr 2024 20:26:00 +0200 From: "Arnd Bergmann" To: "Dan Carpenter" Cc: linux-kernel@vger.kernel.org, "Viresh Kumar" , "Johan Hovold" , "Alex Elder" , "Greg Kroah-Hartman" , "Arnd Bergmann" , "Christophe JAILLET" , greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev Subject: Re: [PATCH 10/11] staging: greybus: change strncpy() to strscpy() Content-Type: text/plain On Thu, Mar 28, 2024, at 16:00, Dan Carpenter wrote: > On Thu, Mar 28, 2024 at 03:04:54PM +0100, Arnd Bergmann wrote: >> Signed-off-by: Arnd Bergmann >> --- >> This is from randconfig testing with random gcc versions, a .config to >> reproduce is at https://pastebin.com/r13yezkU >> --- >> drivers/staging/greybus/fw-management.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c >> index 3054f084d777..35bfdd5f32d2 100644 >> --- a/drivers/staging/greybus/fw-management.c >> +++ b/drivers/staging/greybus/fw-management.c >> @@ -303,13 +303,13 @@ static int fw_mgmt_backend_fw_update_operation(struct fw_mgmt *fw_mgmt, >> struct gb_fw_mgmt_backend_fw_update_request request; >> int ret; >> >> - strncpy(request.firmware_tag, tag, GB_FIRMWARE_TAG_MAX_SIZE); >> + ret = strscpy(request.firmware_tag, tag, GB_FIRMWARE_TAG_MAX_SIZE); > > This needs to be strscpy_pad() or it risks an information leak. Right, I think I misread the code thinking that the strncpy() destination was user provided, but I see now that this copy is from user-provided data into the stack, so the padding is indeed stale stack data. I could not find out whether this gets copied back to userspace, but adding the padding is safer indeed. >> >> /* >> * The firmware-tag should be NULL terminated, otherwise throw error and > ^^^^^^^^^^^^^^^^ > These comments are out of date. > >> * fail. >> */ >> - if (request.firmware_tag[GB_FIRMWARE_TAG_MAX_SIZE - 1] != '\0') { >> + if (ret == -E2BIG) { >> dev_err(fw_mgmt->parent, "backend-update: firmware-tag is not NULL terminated\n"); > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > More out of date prints. I had thought about changing it when I did the patch, but could not come up with anything that describes the error condition better: the cause of the -E2BIG error is still the missing NUL-termination in the provided string. Maybe we should instead not print a warning at all? The general rule is that user triggered operations should not lead to spamming the kernel logs. Arnd