Skip to contentSkip to conversation

dccp: check for ccid in ccid_hc_tx_send_packet

PATCH In review Bragatheswaran Manickavel 3 participants 6 messages Oct 28, 2023 – Nov 2, 2023 1 message not in the archive

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

PATCH 1/1 dccp: check for ccid in ccid_hc_tx_send_packet

ccid_hc_tx_send_packet might be called with a NULL ccid pointer leading to a NULL pointer dereference

Below mentioned commit has similarly changes
commit 276bdb82dedb ("dccp: check ccid before dereferencing")

---
 net/dccp/ccid.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dccp/ccid.h +1 -1
index 105f3734dadb..1015dc2b9392 100644
@@ -163,7 +163,7 @@ static inline int ccid_packet_dequeue_eval(const int return_code)
 static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
 					 struct sk_buff *skb)
 {
-	if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
+	if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
 		return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
 	return CCID_PACKET_SEND_AT_ONCE;
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 28 lines · Bragatheswaran Manickavel

ccid_hc_tx_send_packet might be called with a NULL ccid pointer leading to a NULL pointer dereference

Below mentioned commit has similarly changes
commit 276bdb82dedb ("dccp: check ccid before dereferencing")

---
 net/dccp/ccid.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dccp/ccid.h +1 -2
index 105f3734dadb..1015dc2b9392 100644
@@ -163,7 +163,7 @@ static inline int ccid_packet_dequeue_eval(const int return_code)
 static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
                                         struct sk_buff *skb)
 {
-       if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
+       if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
                return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
        return CCID_PACKET_SEND_AT_ONCE;
 }
--
Quoted 2 lines

2.34.1

If you are willing to fix dccp, I would make sure that some of lockless accesses to dccps_hc_tx_ccid
are also double checked and fixed.

do_dccp_getsockopt() and dccp_get_info()

#2 lore raw
Quoted 35 lines · Eric Dumazet
Quoted 27 lines · Bragatheswaran Manickavel

ccid_hc_tx_send_packet might be called with a NULL ccid pointer leading to a NULL pointer dereference

Below mentioned commit has similarly changes
commit 276bdb82dedb ("dccp: check ccid before dereferencing")

---
  net/dccp/ccid.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/dccp/ccid.h +1 -2
index 105f3734dadb..1015dc2b9392 100644
@@ -163,7 +163,7 @@ static inline int ccid_packet_dequeue_eval(const int return_code)
  static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
                                          struct sk_buff *skb)
  {
-       if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
+       if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
                 return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
         return CCID_PACKET_SEND_AT_ONCE;
  }
--
Quoted 2 lines

2.34.1

If you are willing to fix dccp, I would make sure that some of lockless accesses to dccps_hc_tx_ccid
are also double checked and fixed.

Quoted 1 line

do_dccp_getsockopt() and dccp_get_info()

Hi Eric,

In both do_dccp_getsockopt() and dccp_get_info(), dccps_hc_rx_ccid are checked properly before access.

Thanks,
Bragathe

#3 lore raw
Quoted 38 lines · Bragatheswaran Manickavel
Quoted 35 lines · Eric Dumazet
Quoted 27 lines · Bragatheswaran Manickavel

ccid_hc_tx_send_packet might be called with a NULL ccid pointer leading to a NULL pointer dereference

Below mentioned commit has similarly changes
commit 276bdb82dedb ("dccp: check ccid before dereferencing")

---
  net/dccp/ccid.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/dccp/ccid.h +1 -2
index 105f3734dadb..1015dc2b9392 100644
@@ -163,7 +163,7 @@ static inline int ccid_packet_dequeue_eval(const int return_code)
  static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
                                          struct sk_buff *skb)
  {
-       if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
+       if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
                 return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
         return CCID_PACKET_SEND_AT_ONCE;
  }
--
Quoted 2 lines

2.34.1

If you are willing to fix dccp, I would make sure that some of lockless accesses to dccps_hc_tx_ccid
are also double checked and fixed.

Quoted 8 lines
Quoted 1 line

do_dccp_getsockopt() and dccp_get_info()

Hi Eric,

In both do_dccp_getsockopt() and dccp_get_info(), dccps_hc_rx_ccid are checked properly before access.

Not really, because another thread can change the value at the same time.

Adding checks is not solving races.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 56 lines · Bragatheswaran Manickavel

On 30/10/23 21:19, Eric Dumazet wrote:

On Mon, Oct 30, 2023 at 4:40 PM Bragatheswaran Manickavel <[email protected]> wrote:

On 30/10/23 14:29, Eric Dumazet wrote:

On Sat, Oct 28, 2023 at 4:41 PM Bragatheswaran Manickavel <[email protected]> wrote:

ccid_hc_tx_send_packet might be called with a NULL ccid pointer leading to a NULL pointer dereference

Below mentioned commit has similarly changes
commit 276bdb82dedb ("dccp: check ccid before dereferencing")

---
  net/dccp/ccid.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/dccp/ccid.h +1 -2
index 105f3734dadb..1015dc2b9392 100644
@@ -163,7 +163,7 @@ static inline int ccid_packet_dequeue_eval(const int return_code)
  static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
                                          struct sk_buff *skb)
  {
-       if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
+       if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
                 return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
         return CCID_PACKET_SEND_AT_ONCE;
  }
--

2.34.1

If you are willing to fix dccp, I would make sure that some of lockless accesses to dccps_hc_tx_ccid
are also double checked and fixed.

do_dccp_getsockopt() and dccp_get_info()

Hi Eric,

In both do_dccp_getsockopt() and dccp_get_info(), dccps_hc_rx_ccid are checked properly before access.

Not really, because another thread can change the value at the same time.

Adding checks is not solving races.

Quoted 9 lines

Understood. But when I see function similar to ccid_hc_tx_send_packet all of them has ccid check and few of them have addressed same issue.

dccp_get_info()

        if (dp->dccps_hc_rx_ccid != NULL)
                ccid_hc_rx_get_info(dp->dccps_hc_rx_ccid, sk, info);
        if (dp->dccps_hc_tx_ccid != NULL)
                ccid_hc_tx_get_info(dp->dccps_hc_tx_ccid, sk, info);

All I am saying is that these changes are not correct.

They are simply adding some 'checks' that are unsafe.

Compiler can absolutely fetch dp->dccps_hc_tx_ccid a second time, and a NULL could be read this second time.

Quoted 8 lines

do_dccp_getsockopt()

    ccid_hc_rx_getsockopt
    ccid_hc_tx_getsockopt
    ccid_get_current_rx_ccid
    ccid_get_current_tx_ccid   ===> All of them have ccid check

So, I went on with this changes.
If you have another suggestion of fixing this issue please let me know. I will take a look.

maintainer
#6 lore raw
In reply to Bragatheswaran Manickavel
Quoted 2 lines · Bragatheswaran Manickavel

ccid_hc_tx_send_packet might be called with a NULL ccid pointer leading to a NULL pointer dereference

You should describe how such event could happen.

Quoted 5 lines

Below mentioned commit has similarly changes
commit 276bdb82dedb ("dccp: check ccid before dereferencing")

and add a suitable fixes here.

(beyond taking care of other critical code paths, as reported by Eric).

Thanks!

Paolo