Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Use consttime_memequal instead of memcmp, to pre...



details:   https://anonhg.NetBSD.org/src/rev/75064ae59f17
branches:  trunk
changeset: 360769:75064ae59f17
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Mar 30 07:11:40 2018 +0000

description:
Use consttime_memequal instead of memcmp, to prevent side channels. This
functions returns 1 when the buffers are equal, contrary to memcmp, hence
the !.

diffstat:

 sys/netinet/tcp_input.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (37 lines):

diff -r 0d0e786772c2 -r 75064ae59f17 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Fri Mar 30 06:44:30 2018 +0000
+++ b/sys/netinet/tcp_input.c   Fri Mar 30 07:11:40 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.401 2018/03/29 21:40:53 rmind Exp $    */
+/*     $NetBSD: tcp_input.c,v 1.402 2018/03/30 07:11:40 maxv Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.401 2018/03/29 21:40:53 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.402 2018/03/30 07:11:40 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3236,7 +3236,8 @@
                case TCPOPT_SIGNATURE:
                        if (optlen != TCPOLEN_SIGNATURE)
                                continue;
-                       if (sigp && memcmp(sigp, cp + 2, TCP_SIGLEN))
+                       if (sigp &&
+                           !consttime_memequal(sigp, cp + 2, TCP_SIGLEN))
                                return (-1);
 
                        sigp = sigbuf;
@@ -3269,7 +3270,7 @@
                }
                tcp_fields_to_host(th);
 
-               if (memcmp(sig, sigp, TCP_SIGLEN)) {
+               if (!consttime_memequal(sig, sigp, TCP_SIGLEN)) {
                        TCP_STATINC(TCP_STAT_BADSIG);
                        goto out;
                } else



Home | Main Index | Thread Index | Old Index