From patchwork Fri Jan 11 09:59:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10757597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED16114E5 for ; Fri, 11 Jan 2019 09:59:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB3F029A90 for ; Fri, 11 Jan 2019 09:59:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE9C529A9A; Fri, 11 Jan 2019 09:59:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BBC329A90 for ; Fri, 11 Jan 2019 09:59:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26B918E0002; Fri, 11 Jan 2019 04:59:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 21CFC8E0001; Fri, 11 Jan 2019 04:59:41 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CC7D8E0002; Fri, 11 Jan 2019 04:59:41 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by kanga.kvack.org (Postfix) with ESMTP id CF5E58E0001 for ; Fri, 11 Jan 2019 04:59:40 -0500 (EST) Received: by mail-yb1-f198.google.com with SMTP id g145so6272493yba.13 for ; Fri, 11 Jan 2019 01:59:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=K7BLLCujSs32aWzCL3tA36tp+iHc65Tit6TcVRPMMkw=; b=NluRraIZCCoqKYyQdyMU6HbTIJ8LD6/U/piDm+7Kv8kG9Y8l/s5CaG59vn3ASrDHOb QFaz2VvwbSpxAXF24nDQhpPT6hTJqY0ABQIetE/Afmkz5Zcj7IRdJ6F6O58SlEVT5Slu 4KTNCn6RXO3JaJzy3Zo4e7oe6TFgD3JsOyD5lMyC0eYsPuMkIZBPDbdRqneGtHcYRJPs Szv3ajyyhgJKcPaGc6+iowt6AThRIyAPLpzg1rJ4vQ8bcYcT2FVTwFO+FXAN0z/b7ZFm 66fnkW1P7oNIQRZS+Ys0WLGMolbGPE+1rYzm83KVEjoI7c1NpxCBRdb2ovnB03QSistE rWpw== X-Gm-Message-State: AJcUuke5ujtLzd5yJBxPMfzdhrLZsmA5muO43njWvnTyXOWBmXCcxiYx MzGSyaR1ojl2137MY8gLAJkiSGjo/YOWWFsxUW6S5kZGWk8CjEObFwKNXEAbU1GrdzZXliRGHDS /OViVIlKiqUNKuT8Qa1Bv628KBmHqoz1bS3amR7baVuKfTP/oZl1mm/bR3b24JgStrw== X-Received: by 2002:a0d:c704:: with SMTP id j4mr13519073ywd.382.1547200780282; Fri, 11 Jan 2019 01:59:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN7tajds/ZK8eFhKaWPq2yFsayZC7RuIB9GXVwfX3So4E0DPxoqDMUmHgUgS9g4LS7gi6NuD X-Received: by 2002:a0d:c704:: with SMTP id j4mr13519056ywd.382.1547200779688; Fri, 11 Jan 2019 01:59:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547200779; cv=none; d=google.com; s=arc-20160816; b=nnp10DoLPLwljkGjO9Y2P6KKDz2rOdtCSkGdMUd/l48rA53sNUn3brIRfxeCjkBVPn +uB+4YDv/Fjs9KCjI4zAYMCynbJJJ+GqCm6hnJ8HGWHaxJLbSdX/xuxameODK317R10b ai2YuKZm7EIyZhb301nL5FNtGC/ldhuA/zt7CCXB2s4rdxylPGTHNRR4eP2HrDKicEP6 FRLqy281i0ujp9yQ7vJNZ3HQX7VD949Mse8S8VDLuM5vKE6Ats8TsUJnM7Yj7VsuUOXR gK2q5/dWVCCGcPb/Ft/T69WJxb635b6oas0qN5GrcpgFqeanaJNrDA4uIr2MVrStLSem 0/OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature; bh=K7BLLCujSs32aWzCL3tA36tp+iHc65Tit6TcVRPMMkw=; b=YCRk3vZlq+Pm2NMF8DniOJ1itbD6Ci2sdLhIlNi4OP8/IHoLCndLlVAYeE5awvo/9y NFvqw3rmN/XSeK1lk+b1Xmbiqe1/S0Q+ad/PvRJ6mq5f66uzRlzsx6kfZfBBJLaelfDI vA0jd3Hsbb6yAdZpq6owiuNMCNrbX8OBOALBBNrVIZ9FtL/xL0khe7ABB+GVk1ycs7tN 4O9k6/0YcpbUn6WjzlITMYPTzteKRk9J6Y6VQkqjC2ynbzl/aPu5XaiPutonjbXoUCe2 6opr/W6zvSsTXDLVVZUJRY/O+T9CWP7qfMFtIrxnzM481Ubx05K28e/GEfzr7sYsik39 Uz6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=CCuECRHf; spf=pass (google.com: domain of dan.carpenter@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=dan.carpenter@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id s62si25814079ybc.451.2019.01.11.01.59.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 01:59:39 -0800 (PST) Received-SPF: pass (google.com: domain of dan.carpenter@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=CCuECRHf; spf=pass (google.com: domain of dan.carpenter@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=dan.carpenter@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0B9xTqd185245; Fri, 11 Jan 2019 09:59:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=K7BLLCujSs32aWzCL3tA36tp+iHc65Tit6TcVRPMMkw=; b=CCuECRHf1nmSp1ZXCddltj3G2fXPe7xDuEYRVuDISbu2tcAF1yiwSqgYOC5+PlkNp9aL Avz/pS68kLmUkHNt/7vB9pbk231oEdet6LuBPDpiy0yV+wqSXGtDa1dEq7ZYwm+opUUB q+gnNoP5/1R/cFQUgDwSYFHVUOmp8m9geVeedWWtVVHtFmO76AMQ6gaVWrgWPV3SrX8F hJ3EKRUzIu2Az1XK9zYzJcy4vo+Eobc18wa3yFuf5/6N8BhuKXbBgMPVMe4Bo6Q7DuVM 4hbkLpgW6Z+HBa1T/fuYBaKZ4bsDtgwmbqeVLzrALenXKHUKwMtrF4YOfLGurIDXuOXF hA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2ptm0um1sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Jan 2019 09:59:29 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0B9xNPw010269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Jan 2019 09:59:23 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0B9xMVo014739; Fri, 11 Jan 2019 09:59:22 GMT Received: from kadam (/10.175.19.15) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Jan 2019 01:59:21 -0800 Date: Fri, 11 Jan 2019 12:59:19 +0300 From: Dan Carpenter To: Andrew Morton , Shaohua Li Cc: Huang Ying , Daniel Jordan , Dave Hansen , Stephen Rothwell , Omar Sandoval , Tejun Heo , Andi Kleen , linux-mm@kvack.org, kernel-janitors@vger.kernel.org Subject: [PATCH] mm, swap: Potential NULL dereference in get_swap_page_of_type() Message-ID: <20190111095919.GA1757@kadam> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9132 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901110084 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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}; }