Skip to content

Commit 2f23346

Browse files
Merge pull request #858 from shubhamshinde360/PA-6386-patch-and-upgrade-ruby
(PA-6386) Patch/Upgrade Ruby for CVE-2024-27282
2 parents 80c8c35 + a687390 commit 2f23346

9 files changed

+41
-28
lines changed

configs/components/ruby-2.7.8.rb

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
base = 'resources/patches/ruby_27'
3939
# Patch for https://bugs.ruby-lang.org/issues/14972
4040
pkg.apply_patch "#{base}/net_http_eof_14972_r2.5.patch"
41+
pkg.apply_patch "#{base}/regexp_use_after_free.patch"
4142

4243
pkg.apply_patch "#{base}/uri-redos-cve-2023-36617.patch"
4344

configs/components/ruby-3.2.3.rb configs/components/ruby-3.2.4.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The file name of the ruby component must match the ruby_version
2-
component 'ruby-3.2.3' do |pkg, settings, platform|
3-
pkg.version '3.2.3'
4-
pkg.sha256sum 'af7f1757d9ddb630345988139211f1fd570ff5ba830def1cc7c468ae9b65c9ba'
2+
component 'ruby-3.2.4' do |pkg, settings, platform|
3+
pkg.version '3.2.4'
4+
pkg.sha256sum 'c72b3c5c30482dca18b0f868c9075f3f47d8168eaf626d4e682ce5b59c858692'
55

66
# rbconfig-update is used to munge rbconfigs after the fact.
77
pkg.add_source("file://resources/files/ruby/rbconfig-update.rb")

configs/projects/agent-runtime-main.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project 'agent-runtime-main' do |proj|
22

33
# Set preferred component versions if they differ from defaults:
4-
proj.setting :ruby_version, '3.2.3'
4+
proj.setting :ruby_version, '3.2.4'
55
proj.setting :rubygem_deep_merge_version, '1.2.2'
66
proj.setting :rubygem_highline_version, '3.0.1'
77
proj.setting :rubygem_hocon_version, '1.4.0'

configs/projects/pdk-runtime.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
proj.setting(:includedir, File.join(proj.prefix, 'include'))
4949
proj.setting(:bindir, File.join(proj.prefix, 'bin'))
5050

51-
proj.setting(:ruby_version, '3.2.3')
51+
proj.setting(:ruby_version, '3.2.4')
5252
proj.setting(:ruby_major_version, 3)
5353
proj.setting(:ruby_api, '3.2.0')
5454

configs/projects/pe-bolt-server-runtime-main.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Once we are no longer using ruby 2.5 we can update.
77
proj.setting(:no_doc, true)
88

9-
proj.setting(:ruby_version, '3.2.3')
9+
proj.setting(:ruby_version, '3.2.4')
1010
proj.setting(:openssl_version, '3.0')
1111

1212
# We enable legacy algorithms for winrm transport. Currently the winrm transport

configs/projects/pe-installer-runtime-main.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project 'pe-installer-runtime-main' do |proj|
2-
proj.setting(:ruby_version, '3.2.3')
2+
proj.setting(:ruby_version, '3.2.4')
33
proj.setting(:openssl_version, '3.0')
44
# NLTM uses MD4 unconditionally in its protocol, so legacy algos must be
55
# enabled in OpenSSL >= 3.0 for Bolt's WinRM transport to work.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/regexec.c b/regexec.c
2+
index 73694ab14a..140691ad42 100644
3+
--- a/regexec.c
4+
+++ b/regexec.c
5+
@@ -3449,8 +3449,8 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
6+
CASE(OP_MEMORY_END_PUSH_REC) MOP_IN(OP_MEMORY_END_PUSH_REC);
7+
GET_MEMNUM_INC(mem, p);
8+
STACK_GET_MEM_START(mem, stkp); /* should be before push mem-end. */
9+
- STACK_PUSH_MEM_END(mem, s);
10+
mem_start_stk[mem] = GET_STACK_INDEX(stkp);
11+
+ STACK_PUSH_MEM_END(mem, s);
12+
MOP_OUT;
13+
JUMP;

resources/patches/ruby_32/revert-ruby-double-load-symlink.patch

+17-18
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Date: Wed Feb 22 11:53:00 2023 -0800
2828
which is very unlikely on Windows, so revert it.
2929

3030
diff --git a/load.c b/load.c
31-
index 282bebdb62..636a124d03 100644
31+
index 818665dde8..9a2ae8a8dc 100644
3232
--- a/load.c
3333
+++ b/load.c
3434
@@ -157,12 +157,6 @@ get_loaded_features(rb_vm_t *vm)
3535
return vm->loaded_features;
3636
}
37-
37+
3838
-static VALUE
3939
-get_loaded_features_realpaths(rb_vm_t *vm)
4040
-{
@@ -47,17 +47,16 @@ index 282bebdb62..636a124d03 100644
4747
@@ -360,8 +354,6 @@ get_loaded_features_index(rb_vm_t *vm)
4848
modified loaded_features. Rebuild the index. */
4949
st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
50-
50+
5151
- VALUE realpaths = vm->loaded_features_realpaths;
5252
- rb_hash_clear(realpaths);
5353
features = vm->loaded_features;
5454
for (i = 0; i < RARRAY_LEN(features); i++) {
5555
VALUE entry, as_str;
56-
@@ -373,15 +365,6 @@ get_loaded_features_index(rb_vm_t *vm)
57-
features_index_add(vm, as_str, INT2FIX(i));
56+
@@ -374,14 +366,6 @@ get_loaded_features_index(rb_vm_t *vm)
5857
}
5958
reset_loaded_features_snapshot(vm);
60-
-
59+
6160
- features = rb_ary_dup(vm->loaded_features_snapshot);
6261
- long j = RARRAY_LEN(features);
6362
- for (i = 0; i < j; i++) {
@@ -69,28 +68,28 @@ index 282bebdb62..636a124d03 100644
6968
}
7069
return vm->loaded_features_index;
7170
}
72-
@@ -1158,8 +1141,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
71+
@@ -1161,8 +1145,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
7372
char *volatile ftptr = 0;
7473
VALUE path;
7574
volatile VALUE saved_path;
7675
- volatile VALUE realpath = 0;
7776
- VALUE realpaths = get_loaded_features_realpaths(th->vm);
7877
volatile bool reset_ext_config = false;
7978
struct rb_ext_config prev_ext_config;
80-
81-
@@ -1192,10 +1173,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
79+
80+
@@ -1192,10 +1174,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
81+
else if (found == 's' && run_static_ext_init(th->vm, RSTRING_PTR(path))) {
8282
result = TAG_RETURN;
8383
}
84-
#endif
8584
- else if (RTEST(rb_hash_aref(realpaths,
8685
- realpath = rb_realpath_internal(Qnil, path, 1)))) {
8786
- result = 0;
8887
- }
8988
else {
9089
switch (found) {
9190
case 'r':
92-
@@ -1249,10 +1226,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
93-
91+
@@ -1249,10 +1227,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
92+
9493
if (result == TAG_RETURN) {
9594
rb_provide_feature(th2->vm, path);
9695
- VALUE real = realpath;
@@ -99,14 +98,14 @@ index 282bebdb62..636a124d03 100644
9998
- }
10099
}
101100
ec->errinfo = saved.errinfo;
102-
103-
@@ -1470,8 +1443,6 @@ Init_load(void)
101+
102+
@@ -1485,8 +1485,6 @@ Init_load(void)
104103
vm->loaded_features = rb_ary_new();
105104
vm->loaded_features_snapshot = rb_ary_hidden_new(0);
106105
vm->loaded_features_index = st_init_numtable();
107106
- vm->loaded_features_realpaths = rb_hash_new();
108107
- rb_obj_hide(vm->loaded_features_realpaths);
109-
108+
110109
rb_define_global_function("load", rb_f_load, -1);
111110
rb_define_global_function("require", rb_f_require, 1);
112111
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
@@ -167,14 +166,14 @@ index 4c2ef9834e..4fa4ec2b54 100644
167166
rb_gc_mark_movable(vm->orig_progname);
168167
RUBY_MARK_MOVABLE_UNLESS_NULL(vm->coverages);
169168
diff --git a/vm_core.h b/vm_core.h
170-
index 4f6e07d818..6b9cfca2cd 100644
169+
index 1842519edd..eb2265c97d 100644
171170
--- a/vm_core.h
172171
+++ b/vm_core.h
173-
@@ -679,7 +679,6 @@ typedef struct rb_vm_struct {
172+
@@ -675,7 +675,6 @@ typedef struct rb_vm_struct {
174173
VALUE expanded_load_path;
175174
VALUE loaded_features;
176175
VALUE loaded_features_snapshot;
177176
- VALUE loaded_features_realpaths;
178177
struct st_table *loaded_features_index;
179178
struct st_table *loading_table;
180-
#if EXTSTATIC
179+
// For running the init function of statically linked

resources/patches/ruby_32/revert_speed_up_rebuilding_loaded_feature_index.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ index de43d022c0..d009a5f64a 100644
132132
rb_gc_mark_movable(vm->orig_progname);
133133
RUBY_MARK_MOVABLE_UNLESS_NULL(vm->coverages);
134134
diff --git a/vm_core.h b/vm_core.h
135-
index b6adeadd87..d86fdbaecd 100644
135+
index a8c1e6b917..1842519edd 100644
136136
--- a/vm_core.h
137137
+++ b/vm_core.h
138-
@@ -680,7 +680,6 @@ typedef struct rb_vm_struct {
138+
@@ -676,7 +676,6 @@ typedef struct rb_vm_struct {
139139
VALUE loaded_features;
140140
VALUE loaded_features_snapshot;
141141
VALUE loaded_features_realpaths;
142142
- VALUE loaded_features_realpath_map;
143143
struct st_table *loaded_features_index;
144144
struct st_table *loading_table;
145-
#if EXTSTATIC
145+
// For running the init function of statically linked

0 commit comments

Comments
 (0)