Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1557641
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants |
| Date | 2017-01-12 18:30 +0100 |
| Message-ID | <sYRmi-6IL-17@gated-at.bofh.it> (permalink) |
| References | <sYPNw-5HL-19@gated-at.bofh.it> <sYPNw-5HL-17@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Jan 12, 2017 at 7:37 AM, Michal Hocko <mhocko@kernel.org> wrote: > From: Michal Hocko <mhocko@suse.com> > > There are many code paths opencoding kvmalloc. Let's use the helper > instead. The main difference to kvmalloc is that those users are usually > not considering all the aspects of the memory allocator. E.g. allocation > requests < 64kB are basically never failing and invoke OOM killer to > satisfy the allocation. This sounds too disruptive for something that > has a reasonable fallback - the vmalloc. On the other hand those > requests might fallback to vmalloc even when the memory allocator would > succeed after several more reclaim/compaction attempts previously. There > is no guarantee something like that happens though. > > This patch converts many of those places to kv[mz]alloc* helpers because > they are more conservative. > > Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> > Cc: Heiko Carstens <heiko.carstens@de.ibm.com> > Cc: Herbert Xu <herbert@gondor.apana.org.au> > Cc: Anton Vorontsov <anton@enomsg.org> > Cc: Colin Cross <ccross@android.com> > Cc: Kees Cook <keescook@chromium.org> > Cc: Tony Luck <tony.luck@intel.com> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> > Cc: Ben Skeggs <bskeggs@redhat.com> > Cc: Kent Overstreet <kent.overstreet@gmail.com> > Cc: Santosh Raspatur <santosh@chelsio.com> > Cc: Hariprasad S <hariprasad@chelsio.com> > Cc: Tariq Toukan <tariqt@mellanox.com> > Cc: Yishai Hadas <yishaih@mellanox.com> > Cc: Dan Williams <dan.j.williams@intel.com> > Cc: Oleg Drokin <oleg.drokin@intel.com> > Cc: Andreas Dilger <andreas.dilger@intel.com> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> > Cc: David Sterba <dsterba@suse.com> > Cc: "Yan, Zheng" <zyan@redhat.com> > Cc: Ilya Dryomov <idryomov@gmail.com> > Cc: Alexander Viro <viro@zeniv.linux.org.uk> > Cc: Alexei Starovoitov <ast@kernel.org> > Cc: Eric Dumazet <eric.dumazet@gmail.com> > Cc: netdev@vger.kernel.org > Signed-off-by: Michal Hocko <mhocko@suse.com> > --- > arch/s390/kvm/kvm-s390.c | 10 ++----- > crypto/lzo.c | 4 +-- > drivers/acpi/apei/erst.c | 8 ++--- > drivers/char/agp/generic.c | 8 +---- > drivers/gpu/drm/nouveau/nouveau_gem.c | 4 +-- > drivers/md/bcache/util.h | 12 ++------ > drivers/net/ethernet/chelsio/cxgb3/cxgb3_defs.h | 3 -- > drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c | 25 ++-------------- > drivers/net/ethernet/chelsio/cxgb3/l2t.c | 2 +- > drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 31 ++++---------------- > drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 ++---- > drivers/net/ethernet/mellanox/mlx4/mr.c | 9 ++---- > drivers/nvdimm/dimm_devs.c | 5 +--- > .../staging/lustre/lnet/libcfs/linux/linux-mem.c | 11 +------ > drivers/xen/evtchn.c | 14 +-------- > fs/btrfs/ctree.c | 9 ++---- > fs/btrfs/ioctl.c | 9 ++---- > fs/btrfs/send.c | 27 ++++++----------- > fs/ceph/file.c | 9 ++---- > fs/select.c | 5 +--- > fs/xattr.c | 27 ++++++----------- > kernel/bpf/hashtab.c | 11 ++----- > lib/iov_iter.c | 5 +--- > mm/frame_vector.c | 5 +--- > net/ipv4/inet_hashtables.c | 6 +--- > net/ipv4/tcp_metrics.c | 5 +--- > net/mpls/af_mpls.c | 5 +--- > net/netfilter/x_tables.c | 34 ++++++---------------- > net/netfilter/xt_recent.c | 5 +--- > net/sched/sch_choke.c | 5 +--- > net/sched/sch_fq_codel.c | 26 ++++------------- > net/sched/sch_hhf.c | 33 ++++++--------------- > net/sched/sch_netem.c | 6 +--- > net/sched/sch_sfq.c | 6 +--- > security/keys/keyctl.c | 22 ++++---------- > 35 files changed, 96 insertions(+), 319 deletions(-) > > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 4f74511015b8..e6bbb33d2956 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -1126,10 +1126,7 @@ static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) > if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX) > return -EINVAL; > > - keys = kmalloc_array(args->count, sizeof(uint8_t), > - GFP_KERNEL | __GFP_NOWARN); > - if (!keys) > - keys = vmalloc(sizeof(uint8_t) * args->count); > + keys = kvmalloc(args->count * sizeof(uint8_t), GFP_KERNEL); Before doing this conversion, can we add a kvmalloc_array() API? This conversion could allow for the reintroduction of integer overflow flaws. (This particular situation isn't at risk since ->count is checked, but I'd prefer we not create a risky set of examples for using kvmalloc.) Besides that: yes please. Less open coding. :) -Kees -- Kees Cook Nexus Security
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/6 v3] kvmalloc Michal Hocko <mhocko@kernel.org> - 2017-01-12 16:50 +0100
[PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Michal Hocko <mhocko@kernel.org> - 2017-01-12 16:50 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants David Sterba <dsterba@suse.cz> - 2017-01-12 17:00 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Christian Borntraeger <borntraeger@de.ibm.com> - 2017-01-12 17:10 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Ilya Dryomov <idryomov@gmail.com> - 2017-01-12 18:00 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Michal Hocko <mhocko@kernel.org> - 2017-01-12 18:20 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Dan Williams <dan.j.williams@intel.com> - 2017-01-12 18:10 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Kees Cook <keescook@chromium.org> - 2017-01-12 18:30 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Michal Hocko <mhocko@kernel.org> - 2017-01-12 18:40 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Michal Hocko <mhocko@kernel.org> - 2017-01-12 18:40 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-01-14 04:10 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Michal Hocko <mhocko@kernel.org> - 2017-01-14 10:10 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-01-12 21:20 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants "Dilger, Andreas" <andreas.dilger@intel.com> - 2017-01-13 02:20 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Leon Romanovsky <leon@kernel.org> - 2017-01-14 12:00 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Michal Hocko <mhocko@kernel.org> - 2017-01-16 08:40 +0100
Re: [PATCH 5/6] treewide: use kv[mz]alloc* rather than opencoded variants Leon Romanovsky <leon@kernel.org> - 2017-01-16 09:30 +0100
[PATCH 4/6] ila: simplify a strange allocation pattern Michal Hocko <mhocko@kernel.org> - 2017-01-12 16:50 +0100
[PATCH 3/6] rhashtable: simplify a strange allocation pattern Michal Hocko <mhocko@kernel.org> - 2017-01-12 16:50 +0100
[PATCH 1/6] mm: introduce kv[mz]alloc helpers Michal Hocko <mhocko@kernel.org> - 2017-01-12 16:50 +0100
Re: [PATCH 1/6] mm: introduce kv[mz]alloc helpers John Hubbard <jhubbard@nvidia.com> - 2017-01-16 05:40 +0100
Re: [PATCH 1/6] mm: introduce kv[mz]alloc helpers Michal Hocko <mhocko@kernel.org> - 2017-01-16 09:50 +0100
Re: [PATCH 1/6] mm: introduce kv[mz]alloc helpers John Hubbard <jhubbard@nvidia.com> - 2017-01-16 20:10 +0100
csiph-web