[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6a83affa-c2b0-4236-92f6-354bb0c7f5de@suse.de>
Date: Wed, 13 Dec 2023 08:07:33 +0100
From: Hannes Reinecke <hare@...e.de>
To: Justin Stitt <justinstitt@...gle.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
Bart Van Assche <bvanassche@....org>
Cc: linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2] scsi: fcoe: use sysfs_match_string over
fcoe_parse_mode
On 12/13/23 00:19, Justin Stitt wrote:
> Instead of copying @buf into a new buffer and carefully managing its
> newline/null-terminating status, we can just use sysfs_match_string()
> as it uses sysfs_streq() internally which handles newline/null-term:
>
> | /**
> | * sysfs_streq - return true if strings are equal, modulo trailing newline
> | * @s1: one string
> | * @s2: another string
> | *
> | * This routine returns true iff two strings are equal, treating both
> | * NUL and newline-then-NUL as equivalent string terminations. It's
> | * geared for use with sysfs input strings, which generally terminate
> | * with newlines but are compared against values without newlines.
> | */
> | bool sysfs_streq(const char *s1, const char *s2)
> | ...
>
> Then entirely drop the now unused fcoe_parse_mode, being careful to
> change if condition from checking for FIP_CONN_TYPE_UNKNOWN to < 0 as
> sysfs_match_string can return -EINVAL. Also check explicitly if
> ctlr->mode is equal to FIP_CONN_TYPE_UNKNOWN -- this is probably
> preferred to "<=" as the behavior is more obvious while maintaining
> functionality.
>
> To get the compiler not to complain, make fip_conn_type_names
> const char * const. Perhaps, this should also be done for
> fcf_state_names.
>
> This also removes an instance of strncpy() which helps [1].
>
> Link: https://github.com/KSPP/linux/issues/90 [1]
> Cc: linux-hardening@...r.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@...gle.com>
> ---
> Changes in v2:
> - update if-cond to check for unknown type (thanks Kees)
> - Link to v1: https://lore.kernel.org/r/20231211-strncpy-drivers-scsi-fcoe-fcoe_sysfs-c-v1-1-73b942238396@google.com
> ---
> Builds upon patch and feedback from [2]:
>
> However, this is different enough to warrant its own patch and not be a
> continuation.
>
> [2]: https://lore.kernel.org/all/9f38f4aa-c6b5-4786-a641-d02d8bd92f7f@acm.org/
> ---
> drivers/scsi/fcoe/fcoe_sysfs.c | 26 ++++----------------------
> 1 file changed, 4 insertions(+), 22 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@...e.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@...e.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Ivo Totev, Andrew McDonald,
Werner Knoblich
Powered by blists - more mailing lists