|
|
ad4e62 |
From e3f30ad646f18c23b95ec1a62ea38f2a7848fb36 Mon Sep 17 00:00:00 2001
|
|
|
ad4e62 |
From: Jim Jagielski <jim@apache.org>
|
|
|
ad4e62 |
Date: Wed, 7 Aug 2019 11:14:58 +0000
|
|
|
ad4e62 |
Subject: [PATCH] Merge r1864526 from trunk:
|
|
|
ad4e62 |
|
|
|
ad4e62 |
* modules/metadata/mod_remoteip.c (remoteip_process_v2_header,
|
|
|
ad4e62 |
remoteip_input_filter): Add sanity checks.
|
|
|
ad4e62 |
|
|
|
ad4e62 |
Submitted by: jorton, Daniel McCarney <cpu letsencrypt.org>
|
|
|
ad4e62 |
|
|
|
ad4e62 |
Submitted by: jorton
|
|
|
ad4e62 |
Reviewed by: jorton, covener, jim
|
|
|
ad4e62 |
|
|
|
ad4e62 |
|
|
|
ad4e62 |
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1864613 13f79535-47bb-0310-9956-ffa450edef68
|
|
|
ad4e62 |
---
|
|
|
ad4e62 |
STATUS | 5 -----
|
|
|
ad4e62 |
modules/metadata/mod_remoteip.c | 36 ++++++++++++++++++++++++---------
|
|
|
ad4e62 |
2 files changed, 27 insertions(+), 14 deletions(-)
|
|
|
ad4e62 |
|
|
|
ad4e62 |
diff --git a/modules/metadata/mod_remoteip.c b/modules/metadata/mod_remoteip.c
|
|
|
ad4e62 |
index 4572ce12a95..a0cbc0ff77c 100644
|
|
|
ad4e62 |
--- a/modules/metadata/mod_remoteip.c
|
|
|
ad4e62 |
+++ b/modules/metadata/mod_remoteip.c
|
|
|
ad4e62 |
@@ -987,15 +987,13 @@ static remoteip_parse_status_t remoteip_process_v2_header(conn_rec *c,
|
|
|
ad4e62 |
return HDR_ERROR;
|
|
|
ad4e62 |
#endif
|
|
|
ad4e62 |
default:
|
|
|
ad4e62 |
- /* unsupported protocol, keep local connection address */
|
|
|
ad4e62 |
- return HDR_DONE;
|
|
|
ad4e62 |
+ /* unsupported protocol */
|
|
|
ad4e62 |
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(10183)
|
|
|
ad4e62 |
+ "RemoteIPProxyProtocol: unsupported protocol %.2hx",
|
|
|
ad4e62 |
+ (unsigned short)hdr->v2.fam);
|
|
|
ad4e62 |
+ return HDR_ERROR;
|
|
|
ad4e62 |
}
|
|
|
ad4e62 |
break; /* we got a sockaddr now */
|
|
|
ad4e62 |
-
|
|
|
ad4e62 |
- case 0x00: /* LOCAL command */
|
|
|
ad4e62 |
- /* keep local connection address for LOCAL */
|
|
|
ad4e62 |
- return HDR_DONE;
|
|
|
ad4e62 |
-
|
|
|
ad4e62 |
default:
|
|
|
ad4e62 |
/* not a supported command */
|
|
|
ad4e62 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(03507)
|
|
|
ad4e62 |
@@ -1087,11 +1085,24 @@ static apr_status_t remoteip_input_filter(ap_filter_t *f,
|
|
|
ad4e62 |
/* try to read a header's worth of data */
|
|
|
ad4e62 |
while (!ctx->done) {
|
|
|
ad4e62 |
if (APR_BRIGADE_EMPTY(ctx->bb)) {
|
|
|
ad4e62 |
- ret = ap_get_brigade(f->next, ctx->bb, ctx->mode, block,
|
|
|
ad4e62 |
- ctx->need - ctx->rcvd);
|
|
|
ad4e62 |
+ apr_off_t got, want = ctx->need - ctx->rcvd;
|
|
|
ad4e62 |
+
|
|
|
ad4e62 |
+ ret = ap_get_brigade(f->next, ctx->bb, ctx->mode, block, want);
|
|
|
ad4e62 |
if (ret != APR_SUCCESS) {
|
|
|
ad4e62 |
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, f->c, APLOGNO(10184)
|
|
|
ad4e62 |
+ "failed reading input");
|
|
|
ad4e62 |
return ret;
|
|
|
ad4e62 |
}
|
|
|
ad4e62 |
+
|
|
|
ad4e62 |
+ ret = apr_brigade_length(ctx->bb, 1, &got;;
|
|
|
ad4e62 |
+ if (ret || got > want) {
|
|
|
ad4e62 |
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, f->c, APLOGNO(10185)
|
|
|
ad4e62 |
+ "RemoteIPProxyProtocol header too long, "
|
|
|
ad4e62 |
+ "got %" APR_OFF_T_FMT " expected %" APR_OFF_T_FMT,
|
|
|
ad4e62 |
+ got, want);
|
|
|
ad4e62 |
+ f->c->aborted = 1;
|
|
|
ad4e62 |
+ return APR_ECONNABORTED;
|
|
|
ad4e62 |
+ }
|
|
|
ad4e62 |
}
|
|
|
ad4e62 |
if (APR_BRIGADE_EMPTY(ctx->bb)) {
|
|
|
ad4e62 |
return block == APR_NONBLOCK_READ ? APR_SUCCESS : APR_EOF;
|
|
|
ad4e62 |
@@ -1139,6 +1150,13 @@ static apr_status_t remoteip_input_filter(ap_filter_t *f,
|
|
|
ad4e62 |
if (ctx->rcvd >= MIN_V2_HDR_LEN) {
|
|
|
ad4e62 |
ctx->need = MIN_V2_HDR_LEN +
|
|
|
ad4e62 |
remoteip_get_v2_len((proxy_header *) ctx->header);
|
|
|
ad4e62 |
+ if (ctx->need > sizeof(proxy_v2)) {
|
|
|
ad4e62 |
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, f->c, APLOGNO(10186)
|
|
|
ad4e62 |
+ "RemoteIPProxyProtocol protocol header length too long");
|
|
|
ad4e62 |
+ f->c->aborted = 1;
|
|
|
ad4e62 |
+ apr_brigade_destroy(ctx->bb);
|
|
|
ad4e62 |
+ return APR_ECONNABORTED;
|
|
|
ad4e62 |
+ }
|
|
|
ad4e62 |
}
|
|
|
ad4e62 |
if (ctx->rcvd >= ctx->need) {
|
|
|
ad4e62 |
psts = remoteip_process_v2_header(f->c, conn_conf,
|