All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfs: Fix fscache volume key rendering for endianness
@ 2022-05-19  7:51 David Howells
  2022-05-19 18:01 ` David Wysochanski
  2022-05-19 20:19 ` David Howells
  0 siblings, 2 replies; 3+ messages in thread
From: David Howells @ 2022-05-19  7:51 UTC (permalink / raw)
  To: trond.myklebust, anna
  Cc: Dave Wysochanski, Jeff Layton, linux-nfs, linux-cachefs,
	torvalds, linux-fsdevel, linux-kernel

Fix fscache volume key rendering for endianness.  Convert the BE numbers in
the address to host-endian before printing them so that they're consistent
if the cache is copied between architectures.

Question: This change could lead to misidentification of a volume directory
in the cache on a LE machine (it's unlikely because the port number as well
as the address numbers all get flipped), but it was introduced in -rc1 in
this cycle so probably isn't in any distro kernels yet.  Should I add a
version number to enforce non-matching?

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Dave Wysochanski <dwysocha@redhat.com>
cc: Trond Myklebust <trond.myklebust@hammerspace.com>
cc: Anna Schumaker <anna@kernel.org>
cc: Jeff Layton <jlayton@kernel.org>
cc: linux-nfs@vger.kernel.org
cc: linux-cachefs@redhat.com
---

 fs/nfs/fscache.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index f73c09a9cf0a..0e5572b192b2 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -54,17 +54,17 @@ static bool nfs_fscache_get_client_key(struct nfs_client *clp,
 
 	switch (clp->cl_addr.ss_family) {
 	case AF_INET:
-		if (!nfs_append_int(key, _len, sin->sin_port) ||
-		    !nfs_append_int(key, _len, sin->sin_addr.s_addr))
+		if (!nfs_append_int(key, _len, ntohs(sin->sin_port)) ||
+		    !nfs_append_int(key, _len, ntohl(sin->sin_addr.s_addr)))
 			return false;
 		return true;
 
 	case AF_INET6:
-		if (!nfs_append_int(key, _len, sin6->sin6_port) ||
-		    !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[0]) ||
-		    !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[1]) ||
-		    !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[2]) ||
-		    !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[3]))
+		if (!nfs_append_int(key, _len, ntohs(sin6->sin6_port)) ||
+		    !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[0])) ||
+		    !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[1])) ||
+		    !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[2])) ||
+		    !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[3])))
 			return false;
 		return true;
 



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfs: Fix fscache volume key rendering for endianness
  2022-05-19  7:51 [PATCH] nfs: Fix fscache volume key rendering for endianness David Howells
@ 2022-05-19 18:01 ` David Wysochanski
  2022-05-19 20:19 ` David Howells
  1 sibling, 0 replies; 3+ messages in thread
From: David Wysochanski @ 2022-05-19 18:01 UTC (permalink / raw)
  To: David Howells
  Cc: Trond Myklebust, anna, Jeff Layton, linux-nfs, linux-cachefs,
	Linus Torvalds, linux-fsdevel, Linux Kernel Mailing List

On Thu, May 19, 2022 at 3:51 AM David Howells <dhowells@redhat.com> wrote:
>
> Fix fscache volume key rendering for endianness.  Convert the BE numbers in
> the address to host-endian before printing them so that they're consistent
> if the cache is copied between architectures.
>
> Question: This change could lead to misidentification of a volume directory
> in the cache on a LE machine (it's unlikely because the port number as well
> as the address numbers all get flipped), but it was introduced in -rc1 in
> this cycle so probably isn't in any distro kernels yet.  Should I add a
> version number to enforce non-matching?
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Dave Wysochanski <dwysocha@redhat.com>
> cc: Trond Myklebust <trond.myklebust@hammerspace.com>
> cc: Anna Schumaker <anna@kernel.org>
> cc: Jeff Layton <jlayton@kernel.org>
> cc: linux-nfs@vger.kernel.org
> cc: linux-cachefs@redhat.com
> ---
>
>  fs/nfs/fscache.c |   14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
> index f73c09a9cf0a..0e5572b192b2 100644
> --- a/fs/nfs/fscache.c
> +++ b/fs/nfs/fscache.c
> @@ -54,17 +54,17 @@ static bool nfs_fscache_get_client_key(struct nfs_client *clp,
>
>         switch (clp->cl_addr.ss_family) {
>         case AF_INET:
> -               if (!nfs_append_int(key, _len, sin->sin_port) ||
> -                   !nfs_append_int(key, _len, sin->sin_addr.s_addr))
> +               if (!nfs_append_int(key, _len, ntohs(sin->sin_port)) ||
> +                   !nfs_append_int(key, _len, ntohl(sin->sin_addr.s_addr)))
>                         return false;
>                 return true;
>
>         case AF_INET6:
> -               if (!nfs_append_int(key, _len, sin6->sin6_port) ||
> -                   !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[0]) ||
> -                   !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[1]) ||
> -                   !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[2]) ||
> -                   !nfs_append_int(key, _len, sin6->sin6_addr.s6_addr32[3]))
> +               if (!nfs_append_int(key, _len, ntohs(sin6->sin6_port)) ||
> +                   !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[0])) ||
> +                   !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[1])) ||
> +                   !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[2])) ||
> +                   !nfs_append_int(key, _len, ntohl(sin6->sin6_addr.s6_addr32[3])))
>                         return false;
>                 return true;
>
>
>

IMO it's not worth versioning in this case but I agree with this change.
Did someone report the "cache copied between architectures" issue, or
is that mostly a theoretical problem you noticed?

Acked-by: Dave Wysochanski <dwysocha@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfs: Fix fscache volume key rendering for endianness
  2022-05-19  7:51 [PATCH] nfs: Fix fscache volume key rendering for endianness David Howells
  2022-05-19 18:01 ` David Wysochanski
@ 2022-05-19 20:19 ` David Howells
  1 sibling, 0 replies; 3+ messages in thread
From: David Howells @ 2022-05-19 20:19 UTC (permalink / raw)
  To: David Wysochanski
  Cc: dhowells, Trond Myklebust, anna, Jeff Layton, linux-nfs,
	linux-cachefs, Linus Torvalds, linux-fsdevel,
	Linux Kernel Mailing List

David Wysochanski <dwysocha@redhat.com> wrote:

> Did someone report the "cache copied between architectures" issue, or
> is that mostly a theoretical problem you noticed?

Ah, I didn't mention.  Checker noticed it (make C=1).

David


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-19 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19  7:51 [PATCH] nfs: Fix fscache volume key rendering for endianness David Howells
2022-05-19 18:01 ` David Wysochanski
2022-05-19 20:19 ` David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.