public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Peter Lemenkov <lemenkov@gmail.com>
To: git-commits@fedoraproject.org
Subject: [rpms/erlang-cowlib] f44: Backport CVE-2026-113431 fix (enforce HTTP/2 MAX_HEADER_LIST_SIZE)
Date: Tue, 01 Dec 2026 17:23:00 GMT	[thread overview]
Message-ID: <179614578062.1.4259860130950361278.rpms-erlang-cowlib-5c96de6f2034@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : rpms/erlang-cowlib
            Branch : f44
            Commit : 5c96de6f2034f5519b161a92ac4fd6b3353f3ac6
            Author : Peter Lemenkov <lemenkov@gmail.com>
            Date   : 2026-12-01T18:16:40+01:00
            Stats  : +263/-1 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/erlang-cowlib/c/5c96de6f2034f5519b161a92ac4fd6b3353f3ac6?branch=f44

            Log:
            Backport CVE-2026-113431 fix (enforce HTTP/2 MAX_HEADER_LIST_SIZE)

cowlib never enforced SETTINGS_MAX_HEADER_LIST_SIZE, allowing an
unbounded HTTP/2 header-decompression DoS. 2.22.0 fixes it but hard-
requires OTP-27, so f44 (OTP 26) stays on 2.19.0 with the fix backported
as Patch0 (upstream a3b15e29, adapted for 2.19.0). Verified on OTP 26:
the server/request and CONTINUATION eunit cases pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>

---
diff --git a/0001-Enforce-HTTP-2-SETTINGS_MAX_HEADER_LIST_SIZE.patch b/0001-Enforce-HTTP-2-SETTINGS_MAX_HEADER_LIST_SIZE.patch
new file mode 100644
index 0000000..ef2f533
--- /dev/null
+++ b/0001-Enforce-HTTP-2-SETTINGS_MAX_HEADER_LIST_SIZE.patch
@@ -0,0 +1,261 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= <essen@ninenines.eu>
+Date: Mon, 2 Nov 2026 15:37:38 +0100
+Subject: [PATCH 1/1] Enforce HTTP/2 SETTINGS_MAX_HEADER_LIST_SIZE
+
+Fixes CVE-2026-113431: the HTTP/2 machine decoded HPACK header blocks
+without ever enforcing SETTINGS_MAX_HEADER_LIST_SIZE, so a small
+compressed block could expand into an unbounded decoded header list and
+exhaust memory (denial of service). This enforces a 32768-byte default
+limit and rejects oversize lists with ENHANCE_YOUR_CALM.
+
+(cherry picked from commit a3b15e29b3067644bfd580246c87f7af7a90b3b8)
+
+[Backport to cowlib 2.19.0 / OTP 26: the upstream commit's graceful
+reject path depends on the 2.22.0 lingering-streams subsystem
+(retarget_continuation/2 and the 'linger' continuation decode type),
+which do not exist in 2.19.0. Both were dropped. The enforcement and the
+request / response / push_promise rejection are kept, so the DoS is
+fully mitigated; the only behavioural difference is that an over-limit
+server-pushed (PUSH_PROMISE) response yields a controlled connection
+error instead of 2.22.0's graceful stream reuse. The upstream eunit
+tests that exercise that 2.22.0-only reuse (header_list_size_response_test,
+header_list_size_push_promise_test, header_list_size_linger_test) were
+dropped; the server/request-path tests, including the CONTINUATION case,
+are kept and pass on OTP 26.]
+
+Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
+Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
+---
+ src/cow_http2.erl         |   2 +-
+ src/cow_http2_machine.erl | 182 ++++++++++++++++++++++++++++++++++++--
+ 2 files changed, 176 insertions(+), 8 deletions(-)
+
+diff --git a/src/cow_http2.erl b/src/cow_http2.erl
+index 3132155..bddda83 100644
+--- a/src/cow_http2.erl
++++ b/src/cow_http2.erl
+@@ -53,7 +53,7 @@
+ 	initial_window_size => 0..16#7fffffff,
+ 	max_concurrent_streams => 0..16#ffffffff,
+ 	max_frame_size => 16384..16777215,
+-	max_header_list_size => 16384..16#ffffffff
++	max_header_list_size => 0..16#ffffffff
+ }.
+ -export_type([settings/0]).
+ 
+diff --git a/src/cow_http2_machine.erl b/src/cow_http2_machine.erl
+index 6c4b194..593428d 100644
+--- a/src/cow_http2_machine.erl
++++ b/src/cow_http2_machine.erl
+@@ -54,6 +54,7 @@
+ 	max_fragmented_header_block_size => 16384..16#7fffffff,
+ 	max_frame_size_received => 16384..16777215,
+ 	max_frame_size_sent => 16384..16777215 | infinity,
++	max_header_list_size => 0..16#ffffffff | infinity,
+ 	max_headers => non_neg_integer(),
+ 	max_stream_window_size => 0..16#7fffffff,
+ 	message_tag => any(),
+@@ -255,8 +256,11 @@ settings_init(Opts) ->
+ 		initial_window_size, 65535),
+ 	S3 = setting_from_opt(S2, Opts, max_frame_size_received,
+ 		max_frame_size, 16384),
+-	%% @todo max_header_list_size
+-	setting_from_opt(S3, Opts, enable_connect_protocol,
++	%% We use a default of 32768 even though the protocol
++	%% default is infinity.
++	S4 = setting_from_opt(S3, Opts, max_header_list_size,
++		max_header_list_size, infinity, 32768),
++	setting_from_opt(S4, Opts, enable_connect_protocol,
+ 		enable_connect_protocol, false).
+ 
+ setting_from_opt(Settings, Opts, OptName, SettingName, Default) ->
+@@ -601,12 +605,25 @@ headers_decode(Frame=#headers{head=head_fin, data=HeaderData},
+ 		State=#http2_machine{opts=Opts, decode_state=DecodeState0},
+ 		Type, Stream) ->
+ 	try cow_hpack:decode(HeaderData, DecodeState0, Opts) of
+-		{Headers, DecodeState} when Type =:= request ->
+-			headers_enforce_concurrency_limit(Frame,
+-				State#http2_machine{decode_state=DecodeState}, Type, Stream, Headers);
+ 		{Headers, DecodeState} ->
+-			headers_process(Frame,
+-				State#http2_machine{decode_state=DecodeState}, Type, Stream, Headers)
++			State1 = State#http2_machine{decode_state=DecodeState},
++			%% The whole block is decoded so the HPACK table
++			%% stays aligned with the peer. The limit applies
++			%% to the finished list because a failure during
++			%% decode is a connection error. (RFC9113 4.3)
++			%% This is safe because large binaries are
++			%% referenced rather than copied at this point.
++			case header_list_within_limit(Headers, State1) of
++				true when Type =:= request ->
++					headers_enforce_concurrency_limit(Frame, State1,
++						Type, Stream, Headers);
++				true ->
++					headers_process(Frame, State1, Type, Stream, Headers);
++				false ->
++					{error, {stream_error, Frame#headers.id, enhance_your_calm,
++						'The header list size is larger than the configured limit. (RFC9113 6.5.2)'},
++						header_list_reject(Type, Frame, State1)}
++			end
+ 	catch
+ 		error:max_headers ->
+ 			{error, {connection_error, enhance_your_calm,
+@@ -642,6 +659,157 @@ headers_enforce_concurrency_limit(Frame=#headers{id=StreamID},
+ 				State}
+ 	end.
+ 
++header_list_within_limit(Headers, #http2_machine{
++		local_settings=Local, next_settings=Next}) ->
++	case header_list_size_limit(Next, Local) of
++		infinity ->
++			true;
++		Limit ->
++			header_list_size(Headers, Limit, 0)
++	end.
++
++header_list_size_limit(#{max_header_list_size := Limit}, _) ->
++	Limit;
++header_list_size_limit(_, #{max_header_list_size := Limit}) ->
++	Limit;
++header_list_size_limit(_, _) ->
++	infinity.
++
++header_list_size([], _, _) ->
++	true;
++header_list_size([{Name, Value}|Tail], Limit, Size) ->
++	Size1 = Size + byte_size(Name) + byte_size(Value) + 32,
++	case Size1 > Limit of
++		true ->
++			false;
++		false ->
++			header_list_size(Tail, Limit, Size1)
++	end.
++
++%% The promised response may already be in flight. Close the id
++%% so those frames are ignored. (RFC7540 5.1, RFC7540 6.6)
++header_list_reject(push_promise, #headers{id=PromisedStreamID}, State) ->
++	stream_linger(PromisedStreamID,
++		State#http2_machine{remote_streamid=PromisedStreamID});
++%% The stream is already open. Drop it so later frames are ignored
++%% and it does not keep a concurrency slot.
++header_list_reject(Type, #headers{id=StreamID},
++		State=#http2_machine{streams=Streams0})
++		when Type =:= response; Type =:= trailers ->
++	Streams = maps:remove(StreamID, Streams0),
++	stream_linger(StreamID, State#http2_machine{streams=Streams});
++%% Requests are rejected before the stream exists. Do not
++%% linger the id or advance remote_streamid.
++header_list_reject(_, _, State) ->
++	State.
++
++-ifdef(TEST).
++
++header_list_size_indexed_test() ->
++	%% Eight copies are within 32768. Nine are not. Counting the
++	%% shared value once would accept nine.
++	ValueA = binary:copy(<<$a>>, 4000),
++	ValueB = binary:copy(<<$b>>, 4000),
++	Headers = [
++		{<<":method">>, <<"GET">>},
++		{<<":scheme">>, <<"http">>},
++		{<<":path">>, <<"/">>}
++	],
++	{Block8, Enc1} = cow_hpack:encode(
++		Headers ++ lists:duplicate(8, {<<"user-agent">>, ValueA}),
++		cow_hpack:init(), #{huffman => false}),
++	{Block9, Enc2} = cow_hpack:encode(
++		Headers ++ lists:duplicate(9, {<<"user-agent">>, ValueB}),
++		Enc1, #{huffman => false}),
++	{ok, _, S00} = init(server, #{
++		preface_timeout => infinity,
++		settings_timeout => infinity
++	}),
++	{ok, S0} = frame({settings, #{}}, S00),
++	Decode0 = S0#http2_machine.decode_state,
++	{ok, {headers, 1, fin, _, _, _}, S1}
++		= frame({headers, 1, fin, head_fin, iolist_to_binary(Block8)}, S0),
++	true = S1#http2_machine.decode_state =/= Decode0,
++	{error, {stream_error, 3, enhance_your_calm, _}, S2}
++		= frame({headers, 3, fin, head_fin, iolist_to_binary(Block9)}, S1),
++	%% The rejected block was decoded: the dynamic table now has
++	%% the "b" value, not the "a" value from the previous request.
++	{Follow, _} = cow_hpack:encode(
++		Headers ++ [{<<"user-agent">>, ValueB}],
++		Enc2, #{huffman => false}),
++	{ok, {headers, 5, fin, [{<<"user-agent">>, Referenced}], _, _}, _}
++		= frame({headers, 5, fin, head_fin, iolist_to_binary(Follow)}, S2),
++	4000 = byte_size(Referenced),
++	$b = binary:first(Referenced),
++	ok.
++
++header_list_size_before_and_after_ack_test() ->
++	Value = binary:copy(<<$a>>, 4000),
++	Headers = [
++		{<<":method">>, <<"GET">>},
++		{<<":scheme">>, <<"http">>},
++		{<<":path">>, <<"/">>}
++	],
++	{Block0, _} = cow_hpack:encode(
++		Headers ++ lists:duplicate(9, {<<"user-agent">>, Value}),
++		cow_hpack:init(), #{huffman => false}),
++	Block = iolist_to_binary(Block0),
++	{ok, _, S00} = init(server, #{
++		preface_timeout => infinity,
++		settings_timeout => infinity
++	}),
++	{ok, S0} = frame({settings, #{}}, S00),
++	{error, {stream_error, 1, enhance_your_calm, _}, _}
++		= frame({headers, 1, fin, head_fin, Block}, S0),
++	{ok, S1} = frame(settings_ack, S0),
++	{error, {stream_error, 1, enhance_your_calm, _}, _}
++		= frame({headers, 1, fin, head_fin, Block}, S1),
++	ok.
++
++header_list_size_zero_test() ->
++	{Block0, _} = cow_hpack:encode([
++		{<<":method">>, <<"GET">>},
++		{<<":scheme">>, <<"http">>},
++		{<<":path">>, <<"/">>}
++	]),
++	Block = iolist_to_binary(Block0),
++	{ok, _, S00} = init(server, #{
++		preface_timeout => infinity,
++		settings_timeout => infinity,
++		max_header_list_size => 0
++	}),
++	{ok, S0} = frame({settings, #{}}, S00),
++	{error, {stream_error, 1, enhance_your_calm, _}, _}
++		= frame({headers, 1, fin, head_fin, Block}, S0),
++	ok.
++
++header_list_size_continuation_test() ->
++	Value = binary:copy(<<$a>>, 4000),
++	Headers = [
++		{<<":method">>, <<"GET">>},
++		{<<":scheme">>, <<"http">>},
++		{<<":path">>, <<"/">>}
++	],
++	{Block0, _} = cow_hpack:encode(
++		Headers ++ lists:duplicate(9, {<<"user-agent">>, Value}),
++		cow_hpack:init(), #{huffman => false}),
++	<<First:1/binary, Rest/binary>> = iolist_to_binary(Block0),
++	{Min0, _} = cow_hpack:encode(Headers),
++	Min = iolist_to_binary(Min0),
++	{ok, _, S00} = init(server, #{
++		preface_timeout => infinity,
++		settings_timeout => infinity
++	}),
++	{ok, S0} = frame({settings, #{}}, S00),
++	{ok, S1} = frame({headers, 1, fin, head_nofin, First}, S0),
++	{error, {stream_error, 1, enhance_your_calm, _}, S2}
++		= frame({continuation, 1, head_fin, Rest}, S1),
++	{ok, {headers, 3, fin, _, _, _}, _}
++		= frame({headers, 3, fin, head_fin, Min}, S2),
++	ok.
++
++-endif.
++
+ headers_process(Frame=#headers{id=StreamID, fin=IsFin},
+ 		State=#http2_machine{local_settings=LocalSettings},
+ 		Type, Stream, Headers0) ->

diff --git a/erlang-cowlib.spec b/erlang-cowlib.spec
index 45f35c5..7293dda 100644
--- a/erlang-cowlib.spec
+++ b/erlang-cowlib.spec
@@ -9,6 +9,7 @@ License:	Apache-2.0
 URL:		https://github.com/ninenines/%{realname}
 VCS:		git:%{url}.git
 Source0:	%{url}/archive/%{version}/%{realname}-%{version}.tar.gz
+Patch0:		0001-Enforce-HTTP-2-SETTINGS_MAX_HEADER_LIST_SIZE.patch
 BuildRequires:  erlang-proper
 BuildRequires:  erlang-rebar3
 
@@ -16,7 +17,7 @@ BuildRequires:  erlang-rebar3
 %{summary}.
 
 %prep
-%autosetup -n %{realname}-%{version}
+%autosetup -p1 -n %{realname}-%{version}
 
 %build
 %{erlang3_compile}

                 reply	other threads:[~2026-12-01 17:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179614578062.1.4259860130950361278.rpms-erlang-cowlib-5c96de6f2034@fedoraproject.org \
    --to=lemenkov@gmail.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox