diff mbox series

selftests/rseq: Fix rseq for cases without glibc support

Message ID 20241210224435.15206-1-rananta@google.com (mailing list archive)
State New, archived
Headers show
Series selftests/rseq: Fix rseq for cases without glibc support | expand

Commit Message

Raghavendra Rao Ananta Dec. 10, 2024, 10:44 p.m. UTC
Currently the rseq constructor, rseq_init(), assumes that glibc always
has the support for rseq symbols (__rseq_size for instance). However,
glibc supports rseq from version 2.35 onwards. As a result, for the
systems that run glibc less than 2.35, the global rseq_size remains
initialized to -1U. When a thread then tries to register for rseq,
get_rseq_min_alloc_size() would end up returning -1U, which is
incorrect. Hence, initialize rseq_size for the cases where glibc doesn't
have the support for rseq symbols.

Cc: stable@vger.kernel.org
Fixes: 73a4f5a704a2 ("selftests/rseq: Fix mm_cid test failure")
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 tools/testing/selftests/rseq/rseq.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)


base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37

Comments

Shuah Khan Jan. 13, 2025, 11:06 p.m. UTC | #1
On 12/10/24 15:44, Raghavendra Rao Ananta wrote:
> Currently the rseq constructor, rseq_init(), assumes that glibc always
> has the support for rseq symbols (__rseq_size for instance). However,
> glibc supports rseq from version 2.35 onwards. As a result, for the
> systems that run glibc less than 2.35, the global rseq_size remains
> initialized to -1U. When a thread then tries to register for rseq,
> get_rseq_min_alloc_size() would end up returning -1U, which is
> incorrect. Hence, initialize rseq_size for the cases where glibc doesn't
> have the support for rseq symbols.
> 
> Cc: stable@vger.kernel.org
> Fixes: 73a4f5a704a2 ("selftests/rseq: Fix mm_cid test failure")
> Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
> ---

Applied to linux_kselftest next for Linux 6.14-rc1 after fixing the
commit if for Fixes tag

thanks,
-- Shuah
Mathieu Desnoyers Jan. 14, 2025, 2:07 p.m. UTC | #2
On 2025-01-13 18:06, Shuah Khan wrote:
> On 12/10/24 15:44, Raghavendra Rao Ananta wrote:
>> Currently the rseq constructor, rseq_init(), assumes that glibc always
>> has the support for rseq symbols (__rseq_size for instance). However,
>> glibc supports rseq from version 2.35 onwards. As a result, for the
>> systems that run glibc less than 2.35, the global rseq_size remains
>> initialized to -1U. When a thread then tries to register for rseq,
>> get_rseq_min_alloc_size() would end up returning -1U, which is
>> incorrect. Hence, initialize rseq_size for the cases where glibc doesn't
>> have the support for rseq symbols.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: 73a4f5a704a2 ("selftests/rseq: Fix mm_cid test failure")
>> Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
>> ---
> 
> Applied to linux_kselftest next for Linux 6.14-rc1 after fixing the
> commit if for Fixes tag

Hi Shuah,

I did not review nor ack this patch. I need to review it carefully
to make sure it does not break anything else moving forward.

Please wait before merging.

Thanks,

Mathieu

> 
> thanks,
> -- Shuah
Mathieu Desnoyers Jan. 14, 2025, 2:27 p.m. UTC | #3
On 2025-01-14 09:07, Mathieu Desnoyers wrote:
> On 2025-01-13 18:06, Shuah Khan wrote:
>> On 12/10/24 15:44, Raghavendra Rao Ananta wrote:
>>> Currently the rseq constructor, rseq_init(), assumes that glibc always
>>> has the support for rseq symbols (__rseq_size for instance). However,
>>> glibc supports rseq from version 2.35 onwards. As a result, for the
>>> systems that run glibc less than 2.35, the global rseq_size remains
>>> initialized to -1U. When a thread then tries to register for rseq,
>>> get_rseq_min_alloc_size() would end up returning -1U, which is
>>> incorrect. Hence, initialize rseq_size for the cases where glibc doesn't
>>> have the support for rseq symbols.
>>>
>>> Cc: stable@vger.kernel.org
>>> Fixes: 73a4f5a704a2 ("selftests/rseq: Fix mm_cid test failure")
>>> Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
>>> ---
>>
>> Applied to linux_kselftest next for Linux 6.14-rc1 after fixing the
>> commit if for Fixes tag
> 
> Hi Shuah,
> 
> I did not review nor ack this patch. I need to review it carefully
> to make sure it does not break anything else moving forward.
> 
> Please wait before merging.

I am preparing an alternative fix which keeps the selftests
code in sync with librseq.

Thanks,

Mathieu

> 
> Thanks,
> 
> Mathieu
> 
>>
>> thanks,
>> -- Shuah
>
Shuah Khan Jan. 14, 2025, 4:12 p.m. UTC | #4
On 1/14/25 07:27, Mathieu Desnoyers wrote:
> On 2025-01-14 09:07, Mathieu Desnoyers wrote:
>> On 2025-01-13 18:06, Shuah Khan wrote:
>>> On 12/10/24 15:44, Raghavendra Rao Ananta wrote:
>>>> Currently the rseq constructor, rseq_init(), assumes that glibc always
>>>> has the support for rseq symbols (__rseq_size for instance). However,
>>>> glibc supports rseq from version 2.35 onwards. As a result, for the
>>>> systems that run glibc less than 2.35, the global rseq_size remains
>>>> initialized to -1U. When a thread then tries to register for rseq,
>>>> get_rseq_min_alloc_size() would end up returning -1U, which is
>>>> incorrect. Hence, initialize rseq_size for the cases where glibc doesn't
>>>> have the support for rseq symbols.
>>>>
>>>> Cc: stable@vger.kernel.org
>>>> Fixes: 73a4f5a704a2 ("selftests/rseq: Fix mm_cid test failure")
>>>> Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
>>>> ---
>>>
>>> Applied to linux_kselftest next for Linux 6.14-rc1 after fixing the
>>> commit if for Fixes tag
>>
>> Hi Shuah,
>>
>> I did not review nor ack this patch. I need to review it carefully
>> to make sure it does not break anything else moving forward.
>>
>> Please wait before merging.
> 
> I am preparing an alternative fix which keeps the selftests
> code in sync with librseq.
> 

Sorry for the mixup. I will go drop this now.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/rseq/rseq.c
index 5b9772cdf265..9eb5356f25fa 100644
--- a/tools/testing/selftests/rseq/rseq.c
+++ b/tools/testing/selftests/rseq/rseq.c
@@ -142,6 +142,16 @@  unsigned int get_rseq_kernel_feature_size(void)
 		return ORIG_RSEQ_FEATURE_SIZE;
 }
 
+static void set_default_rseq_size(void)
+{
+	unsigned int rseq_kernel_feature_size = get_rseq_kernel_feature_size();
+
+	if (rseq_kernel_feature_size < ORIG_RSEQ_ALLOC_SIZE)
+		rseq_size = rseq_kernel_feature_size;
+	else
+		rseq_size = ORIG_RSEQ_ALLOC_SIZE;
+}
+
 int rseq_register_current_thread(void)
 {
 	int rc;
@@ -219,12 +229,7 @@  void rseq_init(void)
 			fallthrough;
 		case ORIG_RSEQ_ALLOC_SIZE:
 		{
-			unsigned int rseq_kernel_feature_size = get_rseq_kernel_feature_size();
-
-			if (rseq_kernel_feature_size < ORIG_RSEQ_ALLOC_SIZE)
-				rseq_size = rseq_kernel_feature_size;
-			else
-				rseq_size = ORIG_RSEQ_ALLOC_SIZE;
+			set_default_rseq_size();
 			break;
 		}
 		default:
@@ -239,8 +244,10 @@  void rseq_init(void)
 		rseq_size = 0;
 		return;
 	}
+
 	rseq_offset = (void *)&__rseq_abi - rseq_thread_pointer();
 	rseq_flags = 0;
+	set_default_rseq_size();
 }
 
 static __attribute__((destructor))