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Y2FuIGJlIGNhbGxlZCBmcm9tIGtlcm5lbF9i aW5kKCkgYWxzbyB3aGljaCBJIHRoaW5rIHdpbGwgbmV2ZXIgYmUgY2FsbGVkIGZvciBSRkNPTU0u DQpTbyB0aGlzIHBhdGNoIGlzIG5vdCByZXF1aXJlZD8gDQoNClRoYW5rcywNCkphZ2FuYXRo
Marcel Holtmann
maintainerHi Jaganath,
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
addr can be NULL and it should not be dereferenced before NULL checking.
Signed-off-by Jaganath Kanakkassery <[email protected]>---
Quoted 7 lines
Quoted 3 lines
if we start changing things here, then we better change the code into something that all the other socket handling code is doing anyway>y. So do the min comparison and copy the data into a local copy of the
sockaddr_rc.And on a side note, I wonder if addr can actually be NULL. It might be interesting to check the generic socket code if this really can happe>n if you provide no address structure to the
bind()system call or if this gets filtered out by the core socket code.I checked generic socket code and it looks like addr will never be NULL when user space calls bind. But this can be called from
kernel_bind()also which I think will never be called for RFCOMM. So this patch is not required?
that is what I thought. However converting it to the same handling using min and copying into local storage might be a good idea. The more pieces in HCI, L2CAP, SCO and RFCOMM sockets that are similar, the better.
Regards
Marcel
Hi Marcel,
Quoted 19 lines · Marcel Holtmann
Hi Jaganath,
Quoted 17 lines
Quoted 16 lines
Quoted 5 lines
addr can be NULL and it should not be dereferenced before NULL checking.
Signed-off-by Jaganath Kanakkassery <[email protected]>---
if we start changing things here, then we better change the code into something that all the other socket handling code is doing anyway>y. So do the min comparison and copy the data into a local copy of the
sockaddr_rc.And on a side note, I wonder if addr can actually be NULL. It might be interesting to check the generic socket code if this really can happe>n if you provide no address structure to the
bind()system call or if this gets filtered out by the core socket code.
Quoted 8 lines
Quoted 5 lines
I checked generic socket code and it looks like addr will never be NULL when user space calls bind.
But this can be called fromkernel_bind()also which I think will never be called for RFCOMM.
So this patch is not required?that is what I thought. However converting it to the same handling using min and copying into local storage might be a good idea.
Could you tell us why this is good idea? I failed to find it in git history/mailing list.
In addition to RFCOMM connect that you mentioned, I found out SCO connect/bind still use the old style in Bluetooth unlikely HCI,L2CAP.
Regards
Chanyeol
Quoted 12 lines
The more pieces in HCI, L2CAP, SCO and RFCOMM sockets that are
similar, the better.Regards
Marcel
--
To unsubscribe from this list: send the line "unsubscribe linux -bluetooth" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marcel Holtmann
maintainerHi Chanyeol,
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 11 lines
Quoted 5 lines
addr can be NULL and it should not be dereferenced before NULL checking.
Signed-off-by Jaganath Kanakkassery <[email protected]>---
if we start changing things here, then we better change the code into something that all the other socket handling code is doing anyway>y. So do the min comparison and copy the data into a local copy of the
sockaddr_rc.Quoted 5 lines
And on a side note, I wonder if addr can actually be NULL. It might be interesting to check the generic socket code if this really can happe>n if you provide no address structure to the
bind()system call or if this gets filtered out by the core socket code.I checked generic socket code and it looks like addr will never be NULL when user space calls bind.
But this can be called fromkernel_bind()also which I think will never be called for RFCOMM.
So this patch is not required?
Quoted 7 lines
Quoted 2 lines
that is what I thought. However converting it to the same handling using min and copying into local storage might be a good idea.
Could you tell us why this is good idea? I failed to find it in git history/mailing list.
In addition to RFCOMM connect that you mentioned, I found out SCO connect/bind still use the old style in Bluetooth unlikely HCI,L2CAP.
it avoids any kind of leakage and allows for an easy extension of the socket data structures if we ever have to.
Regards
Marcel