Add compat flag to allow proper seed checksum order.
authorWayne Davison <wayned@samba.org>
Mon, 11 May 2015 19:36:20 +0000 (12:36 -0700)
committerWayne Davison <wayned@samba.org>
Mon, 11 May 2015 19:36:20 +0000 (12:36 -0700)
Fixes the equivalent of librsync's CVE-2014-8242 issue.

checksum.c
compat.c
options.c

index a1c2aa2447d6c2648e4112bed92e1192b6e2bb16..933b514b39207788f88aa3d50b36bbd5419e461a 100644 (file)
@@ -23,6 +23,7 @@
 
 extern int checksum_seed;
 extern int protocol_version;
+extern int proper_seed_order;
 
 /*
   a simple 32 bit checksum that can be upadted from either end
@@ -54,10 +55,18 @@ void get_checksum2(char *buf, int32 len, char *sum)
        if (protocol_version >= 30) {
                uchar seedbuf[4];
                md5_begin(&m);
-               md5_update(&m, (uchar *)buf, len);
-               if (checksum_seed) {
-                       SIVALu(seedbuf, 0, checksum_seed);
-                       md5_update(&m, seedbuf, 4);
+               if (proper_seed_order) {
+                       if (checksum_seed) {
+                               SIVALu(seedbuf, 0, checksum_seed);
+                               md5_update(&m, seedbuf, 4);
+                       }
+                       md5_update(&m, (uchar *)buf, len);
+               } else {
+                       md5_update(&m, (uchar *)buf, len);
+                       if (checksum_seed) {
+                               SIVALu(seedbuf, 0, checksum_seed);
+                               md5_update(&m, seedbuf, 4);
+                       }
                }
                md5_result(&m, (uchar *)sum);
        } else {
index 2454937f85ff08ef298a31c20c7c756d8c26d6ad..f89d466b91365d49b9d0c4aa8f9e9e3e8ae38a59 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -27,6 +27,7 @@ int inc_recurse = 0;
 int compat_flags = 0;
 int use_safe_inc_flist = 0;
 int want_xattr_optim = 0;
+int proper_seed_order = 0;
 
 extern int am_server;
 extern int am_sender;
@@ -78,6 +79,7 @@ int filesfrom_convert = 0;
 #define CF_SYMLINK_ICONV (1<<2)
 #define CF_SAFE_FLIST   (1<<3)
 #define CF_AVOID_XATTR_OPTIM (1<<4)
+#define CF_CHKSUM_SEED_FIX (1<<5)
 
 static const char *client_info;
 
@@ -271,12 +273,15 @@ void setup_protocol(int f_out,int f_in)
                                compat_flags |= CF_SAFE_FLIST;
                        if (local_server || strchr(client_info, 'x') != NULL)
                                compat_flags |= CF_AVOID_XATTR_OPTIM;
+                       if (local_server || strchr(client_info, 'C') != NULL)
+                               compat_flags |= CF_CHKSUM_SEED_FIX;
                        write_byte(f_out, compat_flags);
                } else
                        compat_flags = read_byte(f_in);
                /* The inc_recurse var MUST be set to 0 or 1. */
                inc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;
                want_xattr_optim = protocol_version >= 31 && !(compat_flags & CF_AVOID_XATTR_OPTIM);
+               proper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;
                if (am_sender) {
                        receiver_symlink_times = am_server
                            ? strchr(client_info, 'L') != NULL
index 19c2b7db10d44c6d05b408071748a469fd6fabcf..4128b598d1dd08334ddeaee5fcceea8153fbb718 100644 (file)
--- a/options.c
+++ b/options.c
@@ -2503,6 +2503,7 @@ void server_options(char **args, int *argc_p)
 #endif
                eFlags[x++] = 'f'; /* flist I/O-error safety support */
                eFlags[x++] = 'x'; /* xattr hardlink optimization not desired */
+               eFlags[x++] = 'C'; /* support checksum seed order fix */
 #undef eFlags
        }