Skip to content

Commit 8565d64

Browse files
committed
Merge tag 'bounds-fixes-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull bounds fixes from Kees Cook: "These are a handful of buffer and array bounds fixes that I've been carrying in preparation for the coming memcpy improvements and the enabling of '-Warray-bounds' globally. There are additional similar fixes in other maintainer's trees, but these ended up getting carried by me. :)" * tag 'bounds-fixes-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: media: omap3isp: Use struct_group() for memcpy() region tpm: vtpm_proxy: Check length to avoid compiler warning alpha: Silence -Warray-bounds warnings m68k: cmpxchg: Dereference matching size intel_th: msu: Use memset_startat() for clearing hw header KVM: x86: Replace memset() "optimization" with normal per-field writes
2 parents d0858cb + fad2783 commit 8565d64

8 files changed

Lines changed: 33 additions & 29 deletions

File tree

arch/alpha/mm/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ pgd_alloc(struct mm_struct *mm)
7676
pmd_t *
7777
__bad_pagetable(void)
7878
{
79-
memset((void *) EMPTY_PGT, 0, PAGE_SIZE);
79+
memset(absolute_pointer(EMPTY_PGT), 0, PAGE_SIZE);
8080
return (pmd_t *) EMPTY_PGT;
8181
}
8282

8383
pte_t
8484
__bad_page(void)
8585
{
86-
memset((void *) EMPTY_PGE, 0, PAGE_SIZE);
86+
memset(absolute_pointer(EMPTY_PGE), 0, PAGE_SIZE);
8787
return pte_mkdirty(mk_pte(virt_to_page(EMPTY_PGE), PAGE_SHARED));
8888
}
8989

@@ -253,7 +253,7 @@ void __init paging_init(void)
253253
free_area_init(max_zone_pfn);
254254

255255
/* Initialize the kernel's ZERO_PGE. */
256-
memset((void *)ZERO_PGE, 0, PAGE_SIZE);
256+
memset(absolute_pointer(ZERO_PGE), 0, PAGE_SIZE);
257257
}
258258

259259
#if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)

arch/m68k/include/asm/cmpxchg.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
#include <linux/irqflags.h>
66

7-
struct __xchg_dummy { unsigned long a[100]; };
8-
#define __xg(x) ((volatile struct __xchg_dummy *)(x))
7+
#define __xg(type, x) ((volatile type *)(x))
98

109
extern unsigned long __invalid_xchg_size(unsigned long, volatile void *, int);
1110

@@ -50,23 +49,23 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
5049
"1:\n\t"
5150
"casb %0,%1,%2\n\t"
5251
"jne 1b"
53-
: "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
52+
: "=&d" (x) : "d" (x), "m" (*__xg(u8, ptr)) : "memory");
5453
break;
5554
case 2:
5655
__asm__ __volatile__
5756
("movew %2,%0\n\t"
5857
"1:\n\t"
5958
"casw %0,%1,%2\n\t"
6059
"jne 1b"
61-
: "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
60+
: "=&d" (x) : "d" (x), "m" (*__xg(u16, ptr)) : "memory");
6261
break;
6362
case 4:
6463
__asm__ __volatile__
6564
("movel %2,%0\n\t"
6665
"1:\n\t"
6766
"casl %0,%1,%2\n\t"
6867
"jne 1b"
69-
: "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
68+
: "=&d" (x) : "d" (x), "m" (*__xg(u32, ptr)) : "memory");
7069
break;
7170
default:
7271
x = __invalid_xchg_size(x, ptr, size);

arch/x86/kvm/emulate.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5395,8 +5395,13 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop)
53955395

53965396
void init_decode_cache(struct x86_emulate_ctxt *ctxt)
53975397
{
5398-
memset(&ctxt->rip_relative, 0,
5399-
(void *)&ctxt->modrm - (void *)&ctxt->rip_relative);
5398+
/* Clear fields that are set conditionally but read without a guard. */
5399+
ctxt->rip_relative = false;
5400+
ctxt->rex_prefix = 0;
5401+
ctxt->lock_prefix = 0;
5402+
ctxt->rep_prefix = 0;
5403+
ctxt->regs_valid = 0;
5404+
ctxt->regs_dirty = 0;
54005405

54015406
ctxt->io_read.pos = 0;
54025407
ctxt->io_read.end = 0;

arch/x86/kvm/kvm_emulate.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,7 @@ struct x86_emulate_ctxt {
336336
fastop_t fop;
337337
};
338338
int (*check_perm)(struct x86_emulate_ctxt *ctxt);
339-
/*
340-
* The following six fields are cleared together,
341-
* the rest are initialized unconditionally in x86_decode_insn
342-
* or elsewhere
343-
*/
339+
344340
bool rip_relative;
345341
u8 rex_prefix;
346342
u8 lock_prefix;

drivers/char/tpm/tpm_vtpm_proxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf,
9191

9292
len = proxy_dev->req_len;
9393

94-
if (count < len) {
94+
if (count < len || len > sizeof(proxy_dev->buffer)) {
9595
mutex_unlock(&proxy_dev->buf_lock);
9696
pr_debug("Invalid size in recv: count=%zd, req_len=%zd\n",
9797
count, len);

drivers/hwtracing/intel_th/msu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,11 @@ static void msc_buffer_clear_hw_header(struct msc *msc)
658658

659659
list_for_each_entry(win, &msc->win_list, entry) {
660660
unsigned int blk;
661-
size_t hw_sz = sizeof(struct msc_block_desc) -
662-
offsetof(struct msc_block_desc, hw_tag);
663661

664662
for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) {
665663
struct msc_block_desc *bdesc = sg_virt(sg);
666664

667-
memset(&bdesc->hw_tag, 0, hw_sz);
665+
memset_startat(bdesc, 0, hw_tag);
668666
}
669667
}
670668
}

drivers/media/platform/omap3isp/ispstat.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ int omap3isp_stat_request_statistics(struct ispstat *stat,
512512
int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
513513
struct omap3isp_stat_data_time32 *data)
514514
{
515-
struct omap3isp_stat_data data64;
515+
struct omap3isp_stat_data data64 = { };
516516
int ret;
517517

518518
ret = omap3isp_stat_request_statistics(stat, &data64);
@@ -521,7 +521,8 @@ int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
521521

522522
data->ts.tv_sec = data64.ts.tv_sec;
523523
data->ts.tv_usec = data64.ts.tv_usec;
524-
memcpy(&data->buf, &data64.buf, sizeof(*data) - sizeof(data->ts));
524+
data->buf = (uintptr_t)data64.buf;
525+
memcpy(&data->frame, &data64.frame, sizeof(data->frame));
525526

526527
return 0;
527528
}

include/uapi/linux/omap3isp.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct omap3isp_h3a_aewb_config {
162162
* struct omap3isp_stat_data - Statistic data sent to or received from user
163163
* @ts: Timestamp of returned framestats.
164164
* @buf: Pointer to pass to user.
165+
* @buf_size: Size of buffer.
165166
* @frame_number: Frame number of requested stats.
166167
* @cur_frame: Current frame number being processed.
167168
* @config_counter: Number of the configuration associated with the data.
@@ -176,10 +177,12 @@ struct omap3isp_stat_data {
176177
struct timeval ts;
177178
#endif
178179
void __user *buf;
179-
__u32 buf_size;
180-
__u16 frame_number;
181-
__u16 cur_frame;
182-
__u16 config_counter;
180+
__struct_group(/* no tag */, frame, /* no attrs */,
181+
__u32 buf_size;
182+
__u16 frame_number;
183+
__u16 cur_frame;
184+
__u16 config_counter;
185+
);
183186
};
184187

185188
#ifdef __KERNEL__
@@ -189,10 +192,12 @@ struct omap3isp_stat_data_time32 {
189192
__s32 tv_usec;
190193
} ts;
191194
__u32 buf;
192-
__u32 buf_size;
193-
__u16 frame_number;
194-
__u16 cur_frame;
195-
__u16 config_counter;
195+
__struct_group(/* no tag */, frame, /* no attrs */,
196+
__u32 buf_size;
197+
__u16 frame_number;
198+
__u16 cur_frame;
199+
__u16 config_counter;
200+
);
196201
};
197202
#endif
198203

0 commit comments

Comments
 (0)