From 6b30d6602cee504c7258b808e3c362cefdf70ffc Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 4 May 2017 11:13:32 -0700 Subject: [PATCH] rgw: verify md5 in post obj Fixes: http://tracker.ceph.com/issues/19739 Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_op.cc | 21 +++++++++++++++++++++ src/rgw/rgw_rest.cc | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index d4a9326c3dd..7a3378cac85 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3440,6 +3440,7 @@ void RGWPostObj::execute() RGWPutObjDataProcessor *filter = nullptr; boost::optional compressor; CompressorRef plugin; + char supplied_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; /* Read in the data from the POST form. */ op_ret = get_params(); @@ -3487,6 +3488,21 @@ void RGWPostObj::execute() return; } + if (supplied_md5_b64) { + char supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1]; + ldout(s->cct, 15) << "supplied_md5_b64=" << supplied_md5_b64 << dendl; + op_ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1], + supplied_md5_b64, supplied_md5_b64 + strlen(supplied_md5_b64)); + ldout(s->cct, 15) << "ceph_armor ret=" << op_ret << dendl; + if (op_ret != CEPH_CRYPTO_MD5_DIGESTSIZE) { + op_ret = -ERR_INVALID_DIGEST; + return; + } + + buf_to_hex((const unsigned char *)supplied_md5_bin, CEPH_CRYPTO_MD5_DIGESTSIZE, supplied_md5); + ldout(s->cct, 15) << "supplied_md5=" << supplied_md5 << dendl; + } + RGWPutObjProcessor_Atomic processor(*static_cast(s->obj_ctx), s->bucket_info, s->bucket, @@ -3561,6 +3577,11 @@ void RGWPostObj::execute() s->obj_size = ofs; + if (supplied_md5_b64 && strcmp(calc_md5, supplied_md5)) { + op_ret = -ERR_BAD_DIGEST; + return; + } + op_ret = store->check_quota(s->bucket_owner.get_id(), s->bucket, user_quota, bucket_quota, s->obj_size); if (op_ret < 0) { diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 140d434e737..6063c2c5b13 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1541,6 +1541,8 @@ int RGWPostObj_ObjStore::verify_params() return -ERR_TOO_LARGE; } + supplied_md5_b64 = s->info.env->get("HTTP_CONTENT_MD5"); + return 0; } -- 2.47.3