All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm, swap: Potential NULL dereference in get_swap_page_of_type()
@ 2019-01-11  9:59 ` Dan Carpenter
  0 siblings, 0 replies; 55+ messages in thread
From: Dan Carpenter @ 2019-01-11  9:59 UTC (permalink / raw)
  To: Andrew Morton, Shaohua Li
  Cc: Huang Ying, Daniel Jordan, Dave Hansen, Stephen Rothwell,
	Omar Sandoval, Tejun Heo, Andi Kleen, linux-mm, kernel-janitors

Smatch complains that the NULL checks on "si" aren't consistent.  This
seems like a real bug because we have not ensured that the type is
valid and so "si" can be NULL.

Fixes: ec8acf20afb8 ("swap: add per-partition lock for swapfile")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 mm/swapfile.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index f0edf7244256..21e92c757205 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1048,9 +1048,12 @@ swp_entry_t get_swap_page_of_type(int type)
 	struct swap_info_struct *si;
 	pgoff_t offset;
 
+	if (type >= nr_swapfiles)
+		goto fail;
+
 	si = swap_info[type];
 	spin_lock(&si->lock);
-	if (si && (si->flags & SWP_WRITEOK)) {
+	if (si->flags & SWP_WRITEOK) {
 		atomic_long_dec(&nr_swap_pages);
 		/* This is called for allocating swap entry, not cache */
 		offset = scan_swap_map(si, 1);
@@ -1061,6 +1064,7 @@ swp_entry_t get_swap_page_of_type(int type)
 		atomic_long_inc(&nr_swap_pages);
 	}
 	spin_unlock(&si->lock);
+fail:
 	return (swp_entry_t) {0};
 }
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2019-02-11  1:02 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11  9:59 [PATCH] mm, swap: Potential NULL dereference in get_swap_page_of_type() Dan Carpenter
2019-01-11  9:59 ` Dan Carpenter
2019-01-11 17:41 ` Daniel Jordan
2019-01-11 17:41   ` Daniel Jordan
2019-01-11 23:20   ` Andrea Parri
2019-01-11 23:20     ` Andrea Parri
2019-01-14 22:25     ` Daniel Jordan
2019-01-14 22:25       ` Daniel Jordan
2019-01-15  0:23       ` [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs Daniel Jordan
2019-01-15  0:23         ` Daniel Jordan
2019-01-15  1:17         ` Andrea Parri
2019-01-15  1:17           ` Andrea Parri
2019-01-30  6:26         ` Andrew Morton
2019-01-30  6:26           ` Andrew Morton
2019-01-31  1:52           ` Daniel Jordan
2019-01-31  1:52             ` Daniel Jordan
2019-01-31  2:44             ` [PATCH v2] mm, swap: bounds check swap_info array " Daniel Jordan
2019-01-31  2:44               ` Daniel Jordan
2019-01-31  2:48           ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL d Huang, Ying
2019-01-31  2:48             ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Huang, Ying
2019-01-31 20:46             ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Andrew Morton
2019-01-31 20:46               ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Andrew Morton
2019-02-02  7:14               ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Huang, Ying
2019-02-02  7:14                 ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Huang, Ying
2019-02-04 21:37               ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Hugh Dickins
2019-02-04 21:37                 ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Hugh Dickins
2019-02-04 22:26                 ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Matthew Wilcox
2019-02-04 22:26                   ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Matthew Wilcox
2019-02-06  0:14                 ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Huang, Ying
2019-02-06  0:14                   ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Huang, Ying
2019-02-06  0:36                   ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Hugh Dickins
2019-02-06  0:36                     ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Hugh Dickins
2019-02-06  0:58                     ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Huang, Ying
2019-02-06  0:58                       ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Huang, Ying
2019-02-08  0:28                 ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Andrea Parri
2019-02-08  0:28                   ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Andrea Parri
2019-02-11  1:02                   ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NU Huang, Ying
2019-02-11  1:02                     ` About swapoff race patch (was Re: [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs) Huang, Ying
2019-01-30  7:28         ` [PATCH] mm, swap: bounds check swap_info accesses to avoid NULL derefs Dan Carpenter
2019-01-30  7:28           ` Dan Carpenter
2019-01-31  1:55           ` Daniel Jordan
2019-01-31  1:55             ` Daniel Jordan
2019-01-30  9:13         ` Peter Zijlstra
2019-01-30  9:13           ` Peter Zijlstra
2019-01-31  2:00           ` Daniel Jordan
2019-01-31  2:00             ` Daniel Jordan
2019-01-15  0:28       ` [PATCH] mm, swap: Potential NULL dereference in get_swap_page_of_type() Andrea Parri
2019-01-15  0:28         ` Andrea Parri
2019-01-14  2:12   ` Huang, Ying
2019-01-14  2:12     ` Huang, Ying
2019-01-14  2:12     ` Huang, Ying
2019-01-14  8:43   ` Dan Carpenter
2019-01-14  8:43     ` Dan Carpenter
2019-01-14 23:40     ` Daniel Jordan
2019-01-14 23:40       ` Daniel Jordan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.