From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49066C2D0A8 for ; Wed, 23 Sep 2020 05:13:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C2BD821D43 for ; Wed, 23 Sep 2020 05:13:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2BD821D43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D45C76B0003; Wed, 23 Sep 2020 01:13:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF52A6B0055; Wed, 23 Sep 2020 01:13:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0B2B6B005A; Wed, 23 Sep 2020 01:13:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id A6F356B0003 for ; Wed, 23 Sep 2020 01:13:54 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 57CDF181AC9CC for ; Wed, 23 Sep 2020 05:13:54 +0000 (UTC) X-FDA: 77293159188.05.screw56_2600a4627153 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 341951801924E for ; Wed, 23 Sep 2020 05:13:54 +0000 (UTC) X-HE-Tag: screw56_2600a4627153 X-Filterd-Recvd-Size: 3372 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Sep 2020 05:13:53 +0000 (UTC) IronPort-SDR: +aIFtOX5zsSJmTfymrfz2AgYBlABJ/d4CEMzoxHp3lVI8kTPsGkkXwVnrL2pkRs9+LMdp9PpQa i1g3PDChWbgg== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="148536164" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148536164" 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 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: 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