Skip to contentSkip to conversation

Staging: dst: fix 'Client is not allowed' on sparc

PATCH In review Alexander Beregalov 2 participants 3 messages Dec 13, 2009 – Dec 16, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: dst: fix 'Client is not allowed' on sparc

Not for applying, only describe the problem.

There is a warning on sparc
Kernel unaligned access at TPC[6c0dec] inet_getname+0x4c/0xc0
which goes from

	net/ipv4/af_inet.c:
	int inet_getname(
		...
		*uaddr_len = sizeof(*sin);

sizeof(*sin) is 16, but inet_getname sets sa_data_len to 0. That is why client is denied to access the device. inet_getname() does not read uaddr_len, only writes, so move initialization of sa_data_len after it. Make struct saddr aligned similar to
struct __kernel_sockaddr_storage. This fixes the warning.

---
 drivers/staging/dst/export.c |    2 +-
 include/linux/dst.h          |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/dst/export.c +1 -1
index c324230..4644804 100644
@@ -166,12 +166,12 @@ static struct dst_state *dst_accept_client(struct dst_state *st)
 	}
 	new->socket = sock;
 
-	new->ctl.addr.sa_data_len = sizeof(struct sockaddr);
 	err = kernel_getpeername(sock, (struct sockaddr *)&new->ctl.addr,
 			(int *)&new->ctl.addr.sa_data_len);
 	if (err)
 		goto err_out_put;
 
+	new->ctl.addr.sa_data_len = sizeof(struct sockaddr);	
 	new->permissions = dst_check_permissions(st, new);
 	if (new->permissions == 0) {
 		err = -EPERM;
include/linux/dst.h +2 -2
index e26fed8..454b15a 100644
@@ -74,10 +74,10 @@ struct saddr {
 	/* address family, AF_xxx	*/
 	unsigned short		sa_family;
 	/* 14 bytes of protocol address	*/
-	char			sa_data[SADDR_MAX_DATA];
+	char			sa_data[SADDR_MAX_DATA - sizeof(unsigned short)];
 	/* Number of bytes used in sa_data */
 	unsigned short		sa_data_len;
-};
+} __attribute__((aligned(16)));	/* sizeof(struct sockaddr) */
 
 /* Address structure */
 struct dst_network_ctl
Signature · 1 line
1.6.5.6
#1 lore raw

Hi Alexander.

Sorry for late response.
Your patch looks good, I will forward it to GregKH for inclusion. Thank you.

Quoted 61 lines · Alexander Beregalov

Not for applying, only describe the problem.

There is a warning on sparc
Kernel unaligned access at TPC[6c0dec] inet_getname+0x4c/0xc0
which goes from

	net/ipv4/af_inet.c:
	int inet_getname(
		...
		*uaddr_len = sizeof(*sin);

sizeof(*sin) is 16, but inet_getname sets sa_data_len to 0. That is why client is denied to access the device. inet_getname() does not read uaddr_len, only writes, so move initialization of sa_data_len after it. Make struct saddr aligned similar to
struct __kernel_sockaddr_storage. This fixes the warning.

---
 drivers/staging/dst/export.c |    2 +-
 include/linux/dst.h          |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/dst/export.c +1 -1
index c324230..4644804 100644
@@ -166,12 +166,12 @@ static struct dst_state *dst_accept_client(struct dst_state *st)
 	}
 	new->socket = sock;
 
-	new->ctl.addr.sa_data_len = sizeof(struct sockaddr);
 	err = kernel_getpeername(sock, (struct sockaddr *)&new->ctl.addr,
 			(int *)&new->ctl.addr.sa_data_len);
 	if (err)
 		goto err_out_put;
 
+	new->ctl.addr.sa_data_len = sizeof(struct sockaddr);	
 	new->permissions = dst_check_permissions(st, new);
 	if (new->permissions = 0) {
 		err = -EPERM;
include/linux/dst.h +2 -2
index e26fed8..454b15a 100644
@@ -74,10 +74,10 @@ struct saddr {
 	/* address family, AF_xxx	*/
 	unsigned short		sa_family;
 	/* 14 bytes of protocol address	*/
-	char			sa_data[SADDR_MAX_DATA];
+	char			sa_data[SADDR_MAX_DATA - sizeof(unsigned short)];
 	/* Number of bytes used in sa_data */
 	unsigned short		sa_data_len;
-};
+} __attribute__((aligned(16)));	/* sizeof(struct sockaddr) */
 
 /* Address structure */
 struct dst_network_ctl
Signature · 1 line
1.6.5.6
Signature · 1 line
	Evgeniy Polyakov
#2 lore raw

2009/12/16 Evgeniy Polyakov <[email protected]>:

Quoted 4 lines

Hi Alexander.

Sorry for late response.
Your patch looks good, I will forward it to GregKH for inclusion.

But how does inet_getname() set sa_data_len to 0.
I can't imagine.
My patch is a workaround, not a fix.

Btw, it does not work on sparc anyway, it needs further digging.

Quoted 68 lines

Thank you.

Quoted 58 lines · Alexander Beregalov

Not for applying, only describe the problem.

There is a warning on sparc
 Kernel unaligned access at TPC[6c0dec] inet_getname+0x4c/0xc0 which goes from
      net/ipv4/af_inet.c:
      int inet_getname(
              ...
              *uaddr_len = sizeof(*sin);

sizeof(*sin) is 16, but inet_getname sets sa_data_len to 0. That is why client is denied to access the device. inet_getname() does not read uaddr_len, only writes, so move initialization of sa_data_len after it. Make struct saddr aligned similar to
struct __kernel_sockaddr_storage. This fixes the warning.

---
 drivers/staging/dst/export.c |    2 +-
 include/linux/dst.h          |    4 ++--

 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/dst/export.c +1 -1
index c324230..4644804 100644
@@ -166,12 +166,12 @@ static struct dst_state *dst_accept_client(struct dst_state *st)
       }
       new->socket = sock;
 
-     new->ctl.addr.sa_data_len = sizeof(struct sockaddr);
       err = kernel_getpeername(sock, (struct sockaddr *)&new->ctl.addr,
                       (int *)&new->ctl.addr.sa_data_len);
       if (err)
               goto err_out_put;
 
+     new->ctl.addr.sa_data_len = sizeof(struct sockaddr);
       new->permissions = dst_check_permissions(st, new);
       if (new->permissions == 0) {
               err = -EPERM;
include/linux/dst.h +2 -2
index e26fed8..454b15a 100644
@@ -74,10 +74,10 @@ struct saddr {
       /* address family, AF_xxx       */
       unsigned short          sa_family;
       /* 14 bytes of protocol address */
-     char                    sa_data[SADDR_MAX_DATA];
+     char                    sa_data[SADDR_MAX_DATA - sizeof(unsigned short)];
       /* Number of bytes used in sa_data */
       unsigned short          sa_data_len;
-};
+} __attribute__((aligned(16)));      /* sizeof(struct sockaddr) */
 
  /* Address structure */
Quoted 3 lines

 struct dst_network_ctl
--
1.6.5.6

--
       Evgeniy Polyakov