Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1804525lqe; Tue, 9 Apr 2024 00:08:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwekE3NVUage8p7FWx1sZiEj9lgaMGJRA0xMm//sL6XBv3LNb9GDrZ9AYeQ6qG133fRp5TomKq6kf2PqNevTsK0IvGgWntsflAnd6bWA== X-Google-Smtp-Source: AGHT+IEJs8zN2StKxhW9KNK9hxTV39Wqnt9tF4CAiLLA+PFDD3eYu2kafRxesNOu48/ItqDtGbND X-Received: by 2002:a17:906:11da:b0:a51:98df:f661 with SMTP id o26-20020a17090611da00b00a5198dff661mr7982150eja.53.1712646495070; Tue, 09 Apr 2024 00:08:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712646495; cv=pass; d=google.com; s=arc-20160816; b=R2fJI0rxFYWT6UvBpeNdp02rIYwk3jjbNYQ3KKRyDwOsMXGdk/ZoRO5O6yonRhWY+w SQtjaymCGjhRuu4/i6kRP0mBC6O38FqHqtUiyvl+Azgaw79remf3cdy7HyhYue16ywNV 0BqU9Cz0Umfk1ahx4NWPcNLhm5kzFjcsHpXNp1bZ3HE/jUjGfZt+dm3IVfz7o23uSONH V0laUGNvPBD0pbydAldQg/k9WHLGQOLTI0WdLC5hGr+OatwAAdi4JC2Aj8al8ZvYc1Yw mxBPlsVn1PewiluxN5WrksKpq8txK65NI5l5qFKEwCsEEFtpJIwBBBGsmNRIT8lJFJQ6 jPvg== 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:dkim-signature; bh=CJdJSJ9hqfff0ogua6mplEDET1TsT3kx5yGSs3bTW+g=; fh=6zzA2WSe2sX+6FEHufmGz932/wOqwy4ntuxyWKQ7S9w=; b=u6VUs5W+sLzvmqFPnQppDQ2dIxZpT3KSGUSJTKABxKgWYEujULNTiCFFEoiLb05rmi 6g2KZMWAPNGRNSoprb16YOWhMyHvbeiFXUt8wHGwdujA1JJ1XBEV9Rp2iz1ssgTVwh0d C0RtnwqZl/n83XkM6Nzjn4DN+BVQT+WT9L0nPLlV+c8JxA/2IZZFSJEbYAi13jl3QP9J gfdVPYJfdmr+lnTG5t+mk0vDrGAnjcFj52eYmF3eVvJPLg/n28oEs8ktZUspXEJsW6bx 5s62uCIuP2+aN9rGOi7Ed7fX5lepDnMvMAtugjUJkyVMfeacvrcYLh+SZ0hQqBpUkKW/ 43Jg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b="bABV0/JD"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=s9nHUdfU; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-135867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135867-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fw12-20020a170906c94c00b00a3dcee78d03si4312113ejb.982.2024.04.09.00.08.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:08:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b="bABV0/JD"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=s9nHUdfU; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-135867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135867-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de 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 064811F24F4F for ; Mon, 8 Apr 2024 19:21:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1691145346; Mon, 8 Apr 2024 19:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="bABV0/JD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="s9nHUdfU" Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (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 E60D1143C59 for ; Mon, 8 Apr 2024 19:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712604054; cv=none; b=S8eGkTrkhK/9uo0EwnLtyX2xB7qjGiztXk52u9Nr4zJ7zuGXmiS/xBatDrZYgalJdYLz5mEtdJa8sOCmeD7V3hmHg/v7jLjxBDSAbADiIfaTIjOpbsuNHUYR+Hau3HgQwJSoshMcDmwXtqROjoMPEJD4FLyCueJtRpnhYmOORPY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712604054; c=relaxed/simple; bh=l/9NaRSN7Lj0BWe71GtBBKD+0KLY6lT3ekZ1kX65dMg=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=HQWCoUrLs0Qei/zHRgo7nQKpC9uJ0KiFsLIbu9j2oXrCox69/jerbFYVgxJHR/Nky5BvvlIQbyIyPQfz39HTvuW6C56tCseagzoCGzZSzAx+PWxb1YKwr6x9P0KoMjCD/ww3E6x4JuHx139DK+G6Df7YRK1th7prvsokxBmyYqM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de; spf=pass smtp.mailfrom=arndb.de; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b=bABV0/JD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=s9nHUdfU; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id 7DB1518000F9; Mon, 8 Apr 2024 15:20:50 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Mon, 08 Apr 2024 15:20:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1712604050; x=1712690450; bh=CJdJSJ9hqf ff0ogua6mplEDET1TsT3kx5yGSs3bTW+g=; b=bABV0/JDgEHSMqz3QJ6eUm4zmY cO4nxZd3AX7G+X+FtEE/wdy/Ha+pX3M9AXJfz0frw9vvDIIrMnmwIT1mhojc3pjW AUVFJohUIVIylRDfggSTq2DnL0anFxM24aKDfMCF9GFC6Y3YNVPyUc2J6vHaZ42j a9lIkbqyVFWjmP9SQzpUjKvNk9W1nyVl7SHcBgtAIFpKA5n8wP8g9wQcJjc3dHcC D3vQ407kQ+IFJFySLotyY7lMcM85DaNhV1vvG4yv/c4x4l8fiGzDR8AxUTh22B1c PUqan9IkfH042oSceCnGz4iP4GUhW5H7q3dAHu286uZJ/Qqe/ko8lJ1fYotA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1712604050; x=1712690450; bh=CJdJSJ9hqfff0ogua6mplEDET1Ts T3kx5yGSs3bTW+g=; b=s9nHUdfUV2i2cnbzc9yXOsWJlzcPsi5bbYfAE7F9zVcT lZAK6m83S7BgMs6udpCelvzXXsg5l7qWyiT9FaSjV5pu/hTiAWpJU/Te4p5PNURL tUVmjaIfhl8J8FKIvwWMEB3XFQhYpQ4T6n6GS5SMmW1feapFfRy4NF+gSc8nAbSF 93untM5v7bo1b3+EHGhaDzaDkScG4UVX0RMyjGZLflfb6EEMcX5c4hpcUJvptqem nSP0DG8RuSBQ0WXi6xUHZOcvwaW1Q2GtH8PMDsXoCX4tOceKOH73+tNtP/IjeQ+S jbWitDWSCC2gxia1X5dSLN18LQkPk8xBwvOFDCYj+g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegiedgudefhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrg htthgvrhhnpeffheeugeetiefhgeethfejgfdtuefggeejleehjeeutefhfeeggefhkedt keetffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grrhhnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8F766B6008F; Mon, 8 Apr 2024 15:20:49 -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: <88009872-377b-4155-aceb-88d36f4a44e4@app.fastmail.com> In-Reply-To: <948ab982-cb4d-46d4-a3c4-cc1c6369eb92@moroto.mountain> References: <20240328140512.4148825-1-arnd@kernel.org> <20240328140512.4148825-4-arnd@kernel.org> <695be581-548f-4e5e-a211-5f3b95568e77@moroto.mountain> <948ab982-cb4d-46d4-a3c4-cc1c6369eb92@moroto.mountain> Date: Mon, 08 Apr 2024 21:20:25 +0200 From: "Arnd Bergmann" To: "Dan Carpenter" Cc: "Arnd Bergmann" , linux-kernel@vger.kernel.org, "Greg Kroah-Hartman" , "Kees Cook" , "Daniel Micay" , linux-staging@lists.linux.dev Subject: Re: [PATCH 03/11] staging: replace weird strncpy() with memcpy() Content-Type: text/plain On Mon, Apr 8, 2024, at 17:59, Dan Carpenter wrote: > On Mon, Apr 08, 2024 at 04:45:55PM +0200, Arnd Bergmann wrote: >> On Thu, Mar 28, 2024, at 17:35, Dan Carpenter wrote: >> >> if (sendbytes > 8) { >> >> memcpy(buf, inquiry_buf, 8); >> >> - strncpy(buf + 8, inquiry_string, sendbytes - 8); >> >> + memcpy(buf + 8, inquiry_string, min(sendbytes, 36) - 8); >> > >> > I think your math is off. The string is 29 characters + NUL. So it >> > should be "min(sendbytes, 38) - 8". You're chopping off the space and >> > the NUL terminator. >> > >> > This only affects pro_formatter_flag code... >> >> The extra two bytes were clearly a mistake in the original version >> at the time it got added to drivers/staging. Note how the code >> immediately below it would overwrite the space and NUL byte again: >> >> if (pro_formatter_flag) { >> if (sendbytes > 36) >> memcpy(buf + 36, formatter_inquiry_str, sendbytes - 36); >> } >> > > Ah. Okay. Fair enough. > > I do think this code is really suspect... What is the point of allowing > sendbytes < 36? But that's not related to your patch. As far as I can tell, the driver tries to emulate the behavior or normal scsi commands that could be issued from userspace through SGIO with a short length. drivers/ata/libata-scsi.c has code to handle INQUIRY as well that is somewhat similar but also different enough that I don't trust the rts5208 version of it. On a separate note, I just noticed that I forgot to put the driver name into the subject line, which I've fixed up for v2 as well now. Arnd