lib/zlib: unpoison DFLTCC output buffers
The constraints of the DFLTCC inline assembly are not precise: they do not
communicate the size of the output buffers to the compiler, so it cannot
automatically instrument it.
Add the manual kmsan_unpoison_memory() calls for the output buffers. The
logic is the same as in [1].
[1] 1f5ddcc009
Link: https://lkml.kernel.org/r/20240621113706.315500-21-iii@linux.ibm.com
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reported-by: Alexander Gordeev <agordeev@linux.ibm.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: <kasan-dev@googlegroups.com>
Cc: Marco Elver <elver@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
4d7b5a2cec
commit
89f42df66c
@ -80,6 +80,7 @@ struct dfltcc_param_v0 {
|
||||
uint8_t csb[1152];
|
||||
};
|
||||
|
||||
static_assert(offsetof(struct dfltcc_param_v0, csb) == 384);
|
||||
static_assert(sizeof(struct dfltcc_param_v0) == 1536);
|
||||
|
||||
#define CVT_CRC32 0
|
||||
|
@ -2,6 +2,8 @@
|
||||
#ifndef DFLTCC_UTIL_H
|
||||
#define DFLTCC_UTIL_H
|
||||
|
||||
#include "dfltcc.h"
|
||||
#include <linux/kmsan-checks.h>
|
||||
#include <linux/zutil.h>
|
||||
|
||||
/*
|
||||
@ -20,6 +22,7 @@ typedef enum {
|
||||
#define DFLTCC_CMPR 2
|
||||
#define DFLTCC_XPND 4
|
||||
#define HBT_CIRCULAR (1 << 7)
|
||||
#define DFLTCC_FN_MASK ((1 << 7) - 1)
|
||||
#define HB_BITS 15
|
||||
#define HB_SIZE (1 << HB_BITS)
|
||||
|
||||
@ -34,6 +37,7 @@ static inline dfltcc_cc dfltcc(
|
||||
)
|
||||
{
|
||||
Byte *t2 = op1 ? *op1 : NULL;
|
||||
unsigned char *orig_t2 = t2;
|
||||
size_t t3 = len1 ? *len1 : 0;
|
||||
const Byte *t4 = op2 ? *op2 : NULL;
|
||||
size_t t5 = len2 ? *len2 : 0;
|
||||
@ -59,6 +63,30 @@ static inline dfltcc_cc dfltcc(
|
||||
: "cc", "memory");
|
||||
t2 = r2; t3 = r3; t4 = r4; t5 = r5;
|
||||
|
||||
/*
|
||||
* Unpoison the parameter block and the output buffer.
|
||||
* This is a no-op in non-KMSAN builds.
|
||||
*/
|
||||
switch (fn & DFLTCC_FN_MASK) {
|
||||
case DFLTCC_QAF:
|
||||
kmsan_unpoison_memory(param, sizeof(struct dfltcc_qaf_param));
|
||||
break;
|
||||
case DFLTCC_GDHT:
|
||||
kmsan_unpoison_memory(param, offsetof(struct dfltcc_param_v0, csb));
|
||||
break;
|
||||
case DFLTCC_CMPR:
|
||||
kmsan_unpoison_memory(param, sizeof(struct dfltcc_param_v0));
|
||||
kmsan_unpoison_memory(
|
||||
orig_t2,
|
||||
t2 - orig_t2 +
|
||||
(((struct dfltcc_param_v0 *)param)->sbb == 0 ? 0 : 1));
|
||||
break;
|
||||
case DFLTCC_XPND:
|
||||
kmsan_unpoison_memory(param, sizeof(struct dfltcc_param_v0));
|
||||
kmsan_unpoison_memory(orig_t2, t2 - orig_t2);
|
||||
break;
|
||||
}
|
||||
|
||||
if (op1)
|
||||
*op1 = t2;
|
||||
if (len1)
|
||||
|
Loading…
Reference in New Issue
Block a user