-
Notifications
You must be signed in to change notification settings - Fork 1.9k
icp: Use explicit_memset() exclusively in gcm_clear_ctx() #17343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7fb3224
to
f4bb561
Compare
The importance of the original patch was overstated in hindsight. I just did a more in-depth analysis of the disassembly of the binary generated by GCC 12.2.1: Decompiling it via dogbolt.com (after reassembling the disassembly into a .o file) produced this:
The bit width of the zero assignments were not made obvious by the decompiler, but from the disassembly, we can see that the assignments are being done to 64-bit fields. Comparing to the original source code, we can see that our missing memset() calls had been inlined. Note that ctx->gcm_tmp was uint32_t[4], but was zeroed as if it were uint64_t[2], which is fine. From a security standpoint, we never had an information leak (at least not when using GCC 12.2.1) and I had been wrong that the compiler had optimized away |
Are you to provide |
@lundman You should already have it. d634d20 introduced it to the code: https://github.com/openzfs/zfs/blob/master/module/icp/algs/modes/modes.c#L150 |
Even better! |
As a side note (outside the scope of this PR) we should consider aliasing ZFS's |
I have no issue with someone doing that. However, the only theoretical benefit would be making the icp binary a few bytes smaller when there is a built-in function at the expense of more code in the repository and slightly longer build times, so I think it should be a low priority unless some theoretical security benefit is found. If one were found, we would also want to update our own Note that an alternative way of implementing Implementing the alternative would require supporting at least ld.bfd, ld.gold, lld and maybe also mold. I had considered using a linker script alias when I implemented |
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove `memset()` operations that sanitize sensitive data before memory is freed for use by the rest of the kernel. When I wrote it, I had assumed that the compiler would not remove the other `memset()` operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when calling `gcm_clear_ctx()` than risk a future compiler remove `memset()` calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens. Signed-off-by: Richard Yao <richard@ryao.dev>
I just pushed a typo fix for the commit message. The code changes are exactly the same as they were in prior pushes. |
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove `memset()` operations that sanitize sensitive data before memory is freed for use by the rest of the kernel. When I wrote it, I had assumed that the compiler would not remove the other `memset()` operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when calling `gcm_clear_ctx()` than risk a future compiler remove `memset()` calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Richard Yao <richard@ryao.dev> Closes openzfs#17343 (cherry picked from commit d8a33bc)
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove `memset()` operations that sanitize sensitive data before memory is freed for use by the rest of the kernel. When I wrote it, I had assumed that the compiler would not remove the other `memset()` operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when calling `gcm_clear_ctx()` than risk a future compiler remove `memset()` calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Richard Yao <richard@ryao.dev> Closes openzfs#17343 (cherry picked from commit d8a33bc)
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove `memset()` operations that sanitize sensitive data before memory is freed for use by the rest of the kernel. When I wrote it, I had assumed that the compiler would not remove the other `memset()` operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when calling `gcm_clear_ctx()` than risk a future compiler remove `memset()` calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Richard Yao <richard@ryao.dev> Closes openzfs#17343 (cherry picked from commit d8a33bc)
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove `memset()` operations that sanitize sensitive data before memory is freed for use by the rest of the kernel. When I wrote it, I had assumed that the compiler would not remove the other `memset()` operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when calling `gcm_clear_ctx()` than risk a future compiler remove `memset()` calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Richard Yao <richard@ryao.dev> Closes #17343 (cherry picked from commit d8a33bc)
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove `memset()` operations that sanitize sensitive data before memory is freed for use by the rest of the kernel. When I wrote it, I had assumed that the compiler would not remove the other `memset()` operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when calling `gcm_clear_ctx()` than risk a future compiler remove `memset()` calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Richard Yao <richard@ryao.dev> Closes #17343 (cherry picked from commit d8a33bc)
Motivation and Context
d634d20 had been intended to fix a potential information leak issue where the compiler's optimization passes appeared to remove
memset()
operations that sanitize sensitive data before memory is freed for use by the rest of the kernel.When I wrote it, I had assumed that the compiler would not remove the other
memset()
operations, but upon reflection, I have realized that this was a bad assumption to make. I would rather have a very slight amount of additional overhead when callinggcm_clear_ctx()
than risk a future compiler removememset()
calls. This is likely to happen if someone decides to try doing link time optimization and the person will not think to audit the assembly output for issues like this, so it is best to preempt the possibility before it happens.Description
memset()
calls were replaced withexplicit_memset()
callsHow Has This Been Tested?
No testing was done since this is trivial. The buildbot can test.
Types of changes
Checklist:
Signed-off-by
.