Re: [PATCH] Staging: dst: fix 'Client is not allowed' on sparc

From: Alexander Beregalov
Date: Wed Dec 16 2009 - 14:06:17 EST


2009/12/16 Evgeniy Polyakov <zbr@xxxxxxxxxxx>:
> 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.

> Thank you.
>
> On Sun, Dec 13, 2009 at 05:55:47PM +0300, Alexander Beregalov (a.beregalov@xxxxxxxxx) wrote:
>>
>> 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(-)
>>
>> diff --git a/drivers/staging/dst/export.c b/drivers/staging/dst/export.c
>> index c324230..4644804 100644
>> --- a/drivers/staging/dst/export.c
>> +++ b/drivers/staging/dst/export.c
>> @@ -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;
>> diff --git a/include/linux/dst.h b/include/linux/dst.h
>> index e26fed8..454b15a 100644
>> --- a/include/linux/dst.h
>> +++ b/include/linux/dst.h
>> @@ -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
>> --
>> 1.6.5.6
>
> --
> Â Â Â ÂEvgeniy Polyakov
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/