Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp148863pxk; Tue, 22 Sep 2020 22:17:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0LfM+7/yq1lgjD1Zm6ad0BfI7Rru76JwO7NSEfwQIOobzY9cl3tAXQU/sQfR4i4G6uWQi X-Received: by 2002:aa7:c511:: with SMTP id o17mr7995489edq.300.1600838276381; Tue, 22 Sep 2020 22:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600838276; cv=none; d=google.com; s=arc-20160816; b=J1DGYC/CeXirxlgx6nRuRGsn2xOa6j439v379Sln3TSNDqm5OYKkGXpyzBZsjNBCsS IblYc5J2qfwPgF5wa1Ds0b3U56xby2pwGvrADqJCspiGC9z9T0rZfucKsNJvjg1p+fM4 wiatrkVpDxccTQK1GlgX6EfDmbJ9TOukNu4AjQ2Ybxs4piy+PK/7Nek5tC8RzRe4ItlN iCGytn5Y0Y3nGyGeRBgJ2osQCIodPzT4GCyVWscg8ChiGbM/Pk3CNr+IXd+HpWv55Quh VOWv5vRaBH1CBfK2lq8/Ev0GpEYwjF2xEa/u1ItNnwxloEioJuTzxkS6W7QHZpjA/hWB Iatw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=Y7KwLy3l+4leJKm47hQAd8Z/X2g7vmVRYruJ0t58O8I=; b=Bh4WxCPDbJjUxxNH+trixusxjLlIHiIH/kddi5MvoBKvFozEp+nwgiI66D3pktxKiz BCH+yPvIjbvSLTkCcH52Xpp0ykcRFR5oQOl04t1MHQ2nAy0bgoOor/nBLb+XHmWLJEL3 lI0MP8dhafRdF4JW0zG1KUpPnALO1Tro/G8il4sU5QTLQa305Es2HBBqTsrYb97QGvKB iXHWbA2x1vfQYzSIzbAF/YujI37kL+sGgfjc4M0LCo60KKEJnr1JLu3MFP/QHsqOUhcp 99zHmlckujGBuxMIlGaF3p2pzXxOXJJx2isHHBJeL3YjpOwsI/rbfNIfCfS++bTkfBeG LhVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si11724998edq.83.2020.09.22.22.17.33; Tue, 22 Sep 2020 22:17:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726998AbgIWFNw (ORCPT + 99 others); Wed, 23 Sep 2020 01:13:52 -0400 Received: from mga18.intel.com ([134.134.136.126]:43015 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726834AbgIWFNv (ORCPT ); Wed, 23 Sep 2020 01:13:51 -0400 IronPort-SDR: 7rKLNpeg5Dyww1fNIImmEYY/cQPR+Z/Yh5gyZDw5xsuLAXTD2joJ1LtbXTiXgx9SnmOMhSyFWa n93ugt2SWmOw== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="148536163" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148536163" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 22:13:51 -0700 IronPort-SDR: fWVFHrh3jdQi9TBRy84Y2llMI6nY6Ouqo+qrEMKnJVDKK5/C8PJ0+HcIEsi4HKK1fndVeJmvts K9Ux9TLOeDzg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="305232785" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.164]) by orsmga003.jf.intel.com with ESMTP; 22 Sep 2020 22:13:50 -0700 From: "Huang\, Ying" To: Rafael Aquini Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: Re: [PATCH] mm: swapfile: avoid split_swap_cluster() NULL pointer dereference References: <20200922184838.978540-1-aquini@redhat.com> <878sd1qllb.fsf@yhuang-dev.intel.com> <20200923043459.GL795820@optiplex-lnx> Date: Wed, 23 Sep 2020 13:13:49 +0800 In-Reply-To: <20200923043459.GL795820@optiplex-lnx> (Rafael Aquini's message of "Wed, 23 Sep 2020 00:34:59 -0400") Message-ID: <87sgb9oz1u.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rafael Aquini writes: > On Wed, Sep 23, 2020 at 10:21:36AM +0800, Huang, Ying wrote: >> Hi, Rafael, >> >> Rafael Aquini writes: >> >> > The swap area descriptor only gets struct swap_cluster_info *cluster_info >> > allocated if the swapfile is backed by non-rotational storage. >> > When the swap area is laid on top of ordinary disk spindles, lock_cluster() >> > will naturally return NULL. >> >> Thanks for reporting. But the bug looks strange. Because in a system >> with only HDD swap devices, during THP swap out, the swap cluster >> shouldn't be allocated, as in >> >> shrink_page_list() >> add_to_swap() >> get_swap_page() >> get_swap_pages() >> swap_alloc_cluster() >> > > The underlying problem is that swap_info_struct.cluster_info is always NULL > on the rotational storage case. Yes. > So, it's very easy to follow that constructions > like this one, in split_swap_cluster > > ... > ci = lock_cluster(si, offset); > cluster_clear_huge(ci); > ... > > will go for a NULL pointer dereference, in that case, given that lock_cluster > reads: > > ... > struct swap_cluster_info *ci; > ci = si->cluster_info; > if (ci) { > ci += offset / SWAPFILE_CLUSTER; > spin_lock(&ci->lock); > } > return ci; > ... But on HDD, we shouldn't call split_swap_cluster() at all, because we will not allocate swap cluster firstly. So, if we run into this, there should be some other bug, we need to figure it out. Best Regards, Huang, Ying