Skip to content

Commit f654f0f

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc fixes from Andrew Morton: "14 fixes" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: kernel/sysctl.c: fix out-of-bounds access when setting file-max mm/util.c: fix strndup_user() comment sh: fix multiple function definition build errors MAINTAINERS: add maintainer and replacing reviewer ARM/NUVOTON NPCM MAINTAINERS: fix bad pattern in ARM/NUVOTON NPCM mm: writeback: use exact memcg dirty counts psi: clarify the units used in pressure files mm/huge_memory.c: fix modifying of page protection by insert_pfn_pmd() hugetlbfs: fix memory leak for resv_map mm: fix vm_fault_t cast in VM_FAULT_GET_HINDEX() lib/lzo: fix bugs for very short or empty input include/linux/bitrev.h: fix constant bitrev kmemleak: powerpc: skip scanning holes in the .bss section lib/string.c: implement a basic bcmp
2 parents 4f1cbe0 + 9002b21 commit f654f0f

File tree

18 files changed

+163
-59
lines changed

18 files changed

+163
-59
lines changed

Documentation/accounting/psi.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ situation from a state where some tasks are stalled but the CPU is
5656
still doing productive work. As such, time spent in this subset of the
5757
stall state is tracked separately and exported in the "full" averages.
5858

59-
The ratios are tracked as recent trends over ten, sixty, and three
60-
hundred second windows, which gives insight into short term events as
61-
well as medium and long term trends. The total absolute stall time is
62-
tracked and exported as well, to allow detection of latency spikes
63-
which wouldn't necessarily make a dent in the time averages, or to
64-
average trends over custom time frames.
59+
The ratios (in %) are tracked as recent trends over ten, sixty, and
60+
three hundred second windows, which gives insight into short term events
61+
as well as medium and long term trends. The total absolute stall time
62+
(in us) is tracked and exported as well, to allow detection of latency
63+
spikes which wouldn't necessarily make a dent in the time averages,
64+
or to average trends over custom time frames.
6565

6666
Cgroup2 interface
6767
=================

Documentation/lzo.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ Byte sequences
102102
dictionary which is empty, and that it will always be
103103
invalid at this place.
104104

105-
17 : bitstream version. If the first byte is 17, the next byte
106-
gives the bitstream version (version 1 only). If the first byte
107-
is not 17, the bitstream version is 0.
105+
17 : bitstream version. If the first byte is 17, and compressed
106+
stream length is at least 5 bytes (length of shortest possible
107+
versioned bitstream), the next byte gives the bitstream version
108+
(version 1 only).
109+
Otherwise, the bitstream version is 0.
108110

109111
18..21 : copy 0..3 literals
110112
state = (byte - 17) = 0..3 [ copy <state> literals ]

MAINTAINERS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,14 +1893,15 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-nomadik.git
18931893
ARM/NUVOTON NPCM ARCHITECTURE
18941894
M: Avi Fishman <avifishman70@gmail.com>
18951895
M: Tomer Maimon <tmaimon77@gmail.com>
1896+
M: Tali Perry <tali.perry1@gmail.com>
18961897
R: Patrick Venture <venture@google.com>
18971898
R: Nancy Yuen <yuenn@google.com>
1898-
R: Brendan Higgins <brendanhiggins@google.com>
1899+
R: Benjamin Fair <benjaminfair@google.com>
18991900
L: openbmc@lists.ozlabs.org (moderated for non-subscribers)
19001901
S: Supported
19011902
F: arch/arm/mach-npcm/
19021903
F: arch/arm/boot/dts/nuvoton-npcm*
1903-
F: include/dt-bindings/clock/nuvoton,npcm7xx-clks.h
1904+
F: include/dt-bindings/clock/nuvoton,npcm7xx-clock.h
19041905
F: drivers/*/*npcm*
19051906
F: Documentation/devicetree/bindings/*/*npcm*
19061907
F: Documentation/devicetree/bindings/*/*/*npcm*

arch/powerpc/kernel/kvm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/kvm_host.h>
2323
#include <linux/init.h>
2424
#include <linux/export.h>
25+
#include <linux/kmemleak.h>
2526
#include <linux/kvm_para.h>
2627
#include <linux/slab.h>
2728
#include <linux/of.h>
@@ -712,6 +713,12 @@ static void kvm_use_magic_page(void)
712713

713714
static __init void kvm_free_tmp(void)
714715
{
716+
/*
717+
* Inform kmemleak about the hole in the .bss section since the
718+
* corresponding pages will be unmapped with DEBUG_PAGEALLOC=y.
719+
*/
720+
kmemleak_free_part(&kvm_tmp[kvm_tmp_index],
721+
ARRAY_SIZE(kvm_tmp) - kvm_tmp_index);
715722
free_reserved_area(&kvm_tmp[kvm_tmp_index],
716723
&kvm_tmp[ARRAY_SIZE(kvm_tmp)], -1, NULL);
717724
}

arch/sh/boards/of-generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ static struct sh_machine_vector __initmv sh_of_generic_mv = {
164164

165165
struct sh_clk_ops;
166166

167-
void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
167+
void __init __weak arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
168168
{
169169
}
170170

171-
void __init plat_irq_setup(void)
171+
void __init __weak plat_irq_setup(void)
172172
{
173173
}

fs/hugetlbfs/inode.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,17 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
755755
umode_t mode, dev_t dev)
756756
{
757757
struct inode *inode;
758-
struct resv_map *resv_map;
758+
struct resv_map *resv_map = NULL;
759759

760-
resv_map = resv_map_alloc();
761-
if (!resv_map)
762-
return NULL;
760+
/*
761+
* Reserve maps are only needed for inodes that can have associated
762+
* page allocations.
763+
*/
764+
if (S_ISREG(mode) || S_ISLNK(mode)) {
765+
resv_map = resv_map_alloc();
766+
if (!resv_map)
767+
return NULL;
768+
}
763769

764770
inode = new_inode(sb);
765771
if (inode) {
@@ -794,8 +800,10 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
794800
break;
795801
}
796802
lockdep_annotate_inode_mutex_key(inode);
797-
} else
798-
kref_put(&resv_map->refs, resv_map_release);
803+
} else {
804+
if (resv_map)
805+
kref_put(&resv_map->refs, resv_map_release);
806+
}
799807

800808
return inode;
801809
}

include/linux/bitrev.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,41 @@ static inline u32 __bitrev32(u32 x)
3434

3535
#define __constant_bitrev32(x) \
3636
({ \
37-
u32 __x = x; \
38-
__x = (__x >> 16) | (__x << 16); \
39-
__x = ((__x & (u32)0xFF00FF00UL) >> 8) | ((__x & (u32)0x00FF00FFUL) << 8); \
40-
__x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \
41-
__x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \
42-
__x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \
43-
__x; \
37+
u32 ___x = x; \
38+
___x = (___x >> 16) | (___x << 16); \
39+
___x = ((___x & (u32)0xFF00FF00UL) >> 8) | ((___x & (u32)0x00FF00FFUL) << 8); \
40+
___x = ((___x & (u32)0xF0F0F0F0UL) >> 4) | ((___x & (u32)0x0F0F0F0FUL) << 4); \
41+
___x = ((___x & (u32)0xCCCCCCCCUL) >> 2) | ((___x & (u32)0x33333333UL) << 2); \
42+
___x = ((___x & (u32)0xAAAAAAAAUL) >> 1) | ((___x & (u32)0x55555555UL) << 1); \
43+
___x; \
4444
})
4545

4646
#define __constant_bitrev16(x) \
4747
({ \
48-
u16 __x = x; \
49-
__x = (__x >> 8) | (__x << 8); \
50-
__x = ((__x & (u16)0xF0F0U) >> 4) | ((__x & (u16)0x0F0FU) << 4); \
51-
__x = ((__x & (u16)0xCCCCU) >> 2) | ((__x & (u16)0x3333U) << 2); \
52-
__x = ((__x & (u16)0xAAAAU) >> 1) | ((__x & (u16)0x5555U) << 1); \
53-
__x; \
48+
u16 ___x = x; \
49+
___x = (___x >> 8) | (___x << 8); \
50+
___x = ((___x & (u16)0xF0F0U) >> 4) | ((___x & (u16)0x0F0FU) << 4); \
51+
___x = ((___x & (u16)0xCCCCU) >> 2) | ((___x & (u16)0x3333U) << 2); \
52+
___x = ((___x & (u16)0xAAAAU) >> 1) | ((___x & (u16)0x5555U) << 1); \
53+
___x; \
5454
})
5555

5656
#define __constant_bitrev8x4(x) \
5757
({ \
58-
u32 __x = x; \
59-
__x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \
60-
__x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \
61-
__x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \
62-
__x; \
58+
u32 ___x = x; \
59+
___x = ((___x & (u32)0xF0F0F0F0UL) >> 4) | ((___x & (u32)0x0F0F0F0FUL) << 4); \
60+
___x = ((___x & (u32)0xCCCCCCCCUL) >> 2) | ((___x & (u32)0x33333333UL) << 2); \
61+
___x = ((___x & (u32)0xAAAAAAAAUL) >> 1) | ((___x & (u32)0x55555555UL) << 1); \
62+
___x; \
6363
})
6464

6565
#define __constant_bitrev8(x) \
6666
({ \
67-
u8 __x = x; \
68-
__x = (__x >> 4) | (__x << 4); \
69-
__x = ((__x & (u8)0xCCU) >> 2) | ((__x & (u8)0x33U) << 2); \
70-
__x = ((__x & (u8)0xAAU) >> 1) | ((__x & (u8)0x55U) << 1); \
71-
__x; \
67+
u8 ___x = x; \
68+
___x = (___x >> 4) | (___x << 4); \
69+
___x = ((___x & (u8)0xCCU) >> 2) | ((___x & (u8)0x33U) << 2); \
70+
___x = ((___x & (u8)0xAAU) >> 1) | ((___x & (u8)0x55U) << 1); \
71+
___x; \
7272
})
7373

7474
#define bitrev32(x) \

include/linux/memcontrol.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ struct mem_cgroup *lock_page_memcg(struct page *page);
566566
void __unlock_page_memcg(struct mem_cgroup *memcg);
567567
void unlock_page_memcg(struct page *page);
568568

569-
/* idx can be of type enum memcg_stat_item or node_stat_item */
569+
/*
570+
* idx can be of type enum memcg_stat_item or node_stat_item.
571+
* Keep in sync with memcg_exact_page_state().
572+
*/
570573
static inline unsigned long memcg_page_state(struct mem_cgroup *memcg,
571574
int idx)
572575
{

include/linux/mm_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ enum vm_fault_reason {
671671

672672
/* Encode hstate index for a hwpoisoned large page */
673673
#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
674-
#define VM_FAULT_GET_HINDEX(x) (((x) >> 16) & 0xf)
674+
#define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
675675

676676
#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \
677677
VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \

include/linux/string.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ extern void * memscan(void *,int,__kernel_size_t);
150150
#ifndef __HAVE_ARCH_MEMCMP
151151
extern int memcmp(const void *,const void *,__kernel_size_t);
152152
#endif
153+
#ifndef __HAVE_ARCH_BCMP
154+
extern int bcmp(const void *,const void *,__kernel_size_t);
155+
#endif
153156
#ifndef __HAVE_ARCH_MEMCHR
154157
extern void * memchr(const void *,int,__kernel_size_t);
155158
#endif

kernel/sysctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static int zero;
128128
static int __maybe_unused one = 1;
129129
static int __maybe_unused two = 2;
130130
static int __maybe_unused four = 4;
131+
static unsigned long zero_ul;
131132
static unsigned long one_ul = 1;
132133
static unsigned long long_max = LONG_MAX;
133134
static int one_hundred = 100;
@@ -1750,7 +1751,7 @@ static struct ctl_table fs_table[] = {
17501751
.maxlen = sizeof(files_stat.max_files),
17511752
.mode = 0644,
17521753
.proc_handler = proc_doulongvec_minmax,
1753-
.extra1 = &zero,
1754+
.extra1 = &zero_ul,
17541755
.extra2 = &long_max,
17551756
},
17561757
{

lib/lzo/lzo1x_compress.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,14 @@ int lzogeneric1x_1_compress(const unsigned char *in, size_t in_len,
291291
{
292292
const unsigned char *ip = in;
293293
unsigned char *op = out;
294+
unsigned char *data_start;
294295
size_t l = in_len;
295296
size_t t = 0;
296297
signed char state_offset = -2;
297298
unsigned int m4_max_offset;
298299

299-
// LZO v0 will never write 17 as first byte,
300-
// so this is used to version the bitstream
300+
// LZO v0 will never write 17 as first byte (except for zero-length
301+
// input), so this is used to version the bitstream
301302
if (bitstream_version > 0) {
302303
*op++ = 17;
303304
*op++ = bitstream_version;
@@ -306,6 +307,8 @@ int lzogeneric1x_1_compress(const unsigned char *in, size_t in_len,
306307
m4_max_offset = M4_MAX_OFFSET_V0;
307308
}
308309

310+
data_start = op;
311+
309312
while (l > 20) {
310313
size_t ll = l <= (m4_max_offset + 1) ? l : (m4_max_offset + 1);
311314
uintptr_t ll_end = (uintptr_t) ip + ll;
@@ -324,7 +327,7 @@ int lzogeneric1x_1_compress(const unsigned char *in, size_t in_len,
324327
if (t > 0) {
325328
const unsigned char *ii = in + in_len - t;
326329

327-
if (op == out && t <= 238) {
330+
if (op == data_start && t <= 238) {
328331
*op++ = (17 + t);
329332
} else if (t <= 3) {
330333
op[state_offset] |= t;

lib/lzo/lzo1x_decompress_safe.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
5454
if (unlikely(in_len < 3))
5555
goto input_overrun;
5656

57-
if (likely(*ip == 17)) {
57+
if (likely(in_len >= 5) && likely(*ip == 17)) {
5858
bitstream_version = ip[1];
5959
ip += 2;
60-
if (unlikely(in_len < 5))
61-
goto input_overrun;
6260
} else {
6361
bitstream_version = 0;
6462
}

lib/string.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,26 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
866866
EXPORT_SYMBOL(memcmp);
867867
#endif
868868

869+
#ifndef __HAVE_ARCH_BCMP
870+
/**
871+
* bcmp - returns 0 if and only if the buffers have identical contents.
872+
* @a: pointer to first buffer.
873+
* @b: pointer to second buffer.
874+
* @len: size of buffers.
875+
*
876+
* The sign or magnitude of a non-zero return value has no particular
877+
* meaning, and architectures may implement their own more efficient bcmp(). So
878+
* while this particular implementation is a simple (tail) call to memcmp, do
879+
* not rely on anything but whether the return value is zero or non-zero.
880+
*/
881+
#undef bcmp
882+
int bcmp(const void *a, const void *b, size_t len)
883+
{
884+
return memcmp(a, b, len);
885+
}
886+
EXPORT_SYMBOL(bcmp);
887+
#endif
888+
869889
#ifndef __HAVE_ARCH_MEMSCAN
870890
/**
871891
* memscan - Find a character in an area of memory.

mm/huge_memory.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,21 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
755755
spinlock_t *ptl;
756756

757757
ptl = pmd_lock(mm, pmd);
758+
if (!pmd_none(*pmd)) {
759+
if (write) {
760+
if (pmd_pfn(*pmd) != pfn_t_to_pfn(pfn)) {
761+
WARN_ON_ONCE(!is_huge_zero_pmd(*pmd));
762+
goto out_unlock;
763+
}
764+
entry = pmd_mkyoung(*pmd);
765+
entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
766+
if (pmdp_set_access_flags(vma, addr, pmd, entry, 1))
767+
update_mmu_cache_pmd(vma, addr, pmd);
768+
}
769+
770+
goto out_unlock;
771+
}
772+
758773
entry = pmd_mkhuge(pfn_t_pmd(pfn, prot));
759774
if (pfn_t_devmap(pfn))
760775
entry = pmd_mkdevmap(entry);
@@ -766,11 +781,16 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
766781
if (pgtable) {
767782
pgtable_trans_huge_deposit(mm, pmd, pgtable);
768783
mm_inc_nr_ptes(mm);
784+
pgtable = NULL;
769785
}
770786

771787
set_pmd_at(mm, addr, pmd, entry);
772788
update_mmu_cache_pmd(vma, addr, pmd);
789+
790+
out_unlock:
773791
spin_unlock(ptl);
792+
if (pgtable)
793+
pte_free(mm, pgtable);
774794
}
775795

776796
vm_fault_t vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
@@ -821,6 +841,20 @@ static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
821841
spinlock_t *ptl;
822842

823843
ptl = pud_lock(mm, pud);
844+
if (!pud_none(*pud)) {
845+
if (write) {
846+
if (pud_pfn(*pud) != pfn_t_to_pfn(pfn)) {
847+
WARN_ON_ONCE(!is_huge_zero_pud(*pud));
848+
goto out_unlock;
849+
}
850+
entry = pud_mkyoung(*pud);
851+
entry = maybe_pud_mkwrite(pud_mkdirty(entry), vma);
852+
if (pudp_set_access_flags(vma, addr, pud, entry, 1))
853+
update_mmu_cache_pud(vma, addr, pud);
854+
}
855+
goto out_unlock;
856+
}
857+
824858
entry = pud_mkhuge(pfn_t_pud(pfn, prot));
825859
if (pfn_t_devmap(pfn))
826860
entry = pud_mkdevmap(entry);
@@ -830,6 +864,8 @@ static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
830864
}
831865
set_pud_at(mm, addr, pud, entry);
832866
update_mmu_cache_pud(vma, addr, pud);
867+
868+
out_unlock:
833869
spin_unlock(ptl);
834870
}
835871

0 commit comments

Comments
 (0)