Received: by 10.223.176.5 with SMTP id f5csp779232wra; Sat, 3 Feb 2018 10:05:14 -0800 (PST) X-Google-Smtp-Source: AH8x227bqgMcmeVa8Mreq03S/rixnvnOJsBFVtYzGUzZVSFa8ml8am56VJQl8N84TgRCGgr+vO28 X-Received: by 10.99.104.194 with SMTP id d185mr34450998pgc.404.1517681114685; Sat, 03 Feb 2018 10:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517681114; cv=none; d=google.com; s=arc-20160816; b=VWyhK/t9d4lkkAQi+39my4lb8QC1kmqFgSBt4uVwLccuJpybTjIB0k1Uf55YNrp5de iA/iSerbYfQ1WXL5AMN7b8xWPAPLN5SOc5UXdsoBzN2uM38BLl3ZayNDBREzqoKzSXm/ 1435pAf2yN6oBLaIlvzcyIa1hQhypt/N5AknFuu6PKkKNbN0lzmE/tVm8vVdFyOyqOGz uRlT+v+WgwMtsIiibGDePRdi/J69Hvw4woM+9+QiQYfxg6T9APCXqo6cDSJcdBjaXh5F BpEa6Exxt7uSAR26Ihrek4Sf3lvBeowMhDB8skNKNEOQfN+MfSKKaaVuXsXT6fByqkQJ MnCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=LDXsf9fOUoBFHO1Y4upIwmC1XyNpOSy7pgyqfY94ExQ=; b=lCcA56e6z7lgxkuYUZyzqAZz4e/aDs0G46TT3SsE1qzjxUU84jmm6I30yw4o74pUFV uPeH3nBudkhaqeQd9k9fj8zQ7cyfK7ZdctW4+u+ZaE4fI1Yk8jzRjlfCrN2tILoeuDlE XQZqutj+13r8o+VLJQmmQ7bTww8SbeDTgdLt2XbhFcAjdZFxrE42vN1A6LqqPCpFUr2j kWxQ0qrsKNUym8LbDVtVaO7U5vH79Nszcd4MBcNAD+Xe9OP00s2co1ScTOCEgCjwpaKX s9s8OqP7lEsGwg5VS4bKCWtBP56mRt9LLFffngOmgIns6mzE5QNSsCLcW5hQcNbVlEEV H2pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AVUzMKh7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7si1521806pgv.172.2018.02.03.10.04.59; Sat, 03 Feb 2018 10:05:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AVUzMKh7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753148AbeBCSCq (ORCPT + 99 others); Sat, 3 Feb 2018 13:02:46 -0500 Received: from mail-bl2nam02on0134.outbound.protection.outlook.com ([104.47.38.134]:35168 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752761AbeBCSAp (ORCPT ); Sat, 3 Feb 2018 13:00:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LDXsf9fOUoBFHO1Y4upIwmC1XyNpOSy7pgyqfY94ExQ=; b=AVUzMKh7NZpfXgIaZAYszlxflEHCqu0OKjuBZ5HnecpMY/weW/wB6AldVZm0S3UJ2scW3QBpbmGySx/pk7pwBMSKRN9+Wow+NAWMR1vjANjD3OTI7Z0m+Zd/IfIIYT8f5sddg1kJLCZy95y7F5KF6QVH2h6QCV88IRDxG1eM0Zg= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1090.namprd21.prod.outlook.com (52.132.24.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.1; Sat, 3 Feb 2018 18:00:39 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:00:39 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Tetsuo Handa , Aliaksei Karaliou , Glauber Costa , Al Viro , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 020/110] mm,vmscan: Make unregister_shrinker() no-op if register_shrinker() failed. Thread-Topic: [PATCH AUTOSEL for 4.14 020/110] mm,vmscan: Make unregister_shrinker() no-op if register_shrinker() failed. Thread-Index: AQHTnRjkVPK7EMW4mkmM+vAqvB5jeQ== Date: Sat, 3 Feb 2018 18:00:36 +0000 Message-ID: <20180203180015.29073-20-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BL0PR2101MB1090;6:cRtH+soCT9xvZX0v1/kPphgqy8h7BqD9qdLP5j8fopam91tQWUK+YaZyKZqO0Ws6zyZcIWjYFCOBR1wLJcIAzawB3buzbVpLxtQkIT2hkGx1c2G0giQvAYcyjbg9ZM64HEdNwKaTitdRjwUdI2aAPfYUcMIwBh4m1394oASWeG60VXtevcHglQtuBrcA0r1jqO6ToyXmTjLLIHEPOZIyuhKxImMiJstise5HOev98vs3if12IQSPneSSxaRl8ugDmcYFWXVLUoCJUIRNdzFpoMQ7ApU1lg7jAGh4aoLEFMvW5NUcuV6BlLFtOcHdZbAAoyYtF4cuiySFCURvQOL5RyfbKyXyR2XoqGt0pfy740p3biY7z1wGwNKwWaG4Ngb+;5:DbB834ThGeTBia+Xqi5DmZVAo16Yv+JGNMHsxakw6Get2/J7wHMV/DSg0xnwBtxXWqBf9PqlQbl7ZoulX6R6BQMXChvnf52p3fg89/469pD/sLMlKMTCi/ye+knJPv+aJ1La2XUHuzXTm0BucGramHwqJ+eGNdO/F3G2GsRm40I=;24:E/cv2VNphg1ZQFriHFm94OrYpOZsY56bE27EjHhD5Mn70+E2x1k4goc1V9KHktjflrqliA1cxsEqRu6e6PzrKM/WjIQyXNtbvD1Cew9Owb0=;7:DnRJZj9f39jB5iZLXtRWq5EcWwOf7AAgFFQR5+aFgspMJGRsV5zvAp2tM0Sko9HR6eon+iiu1nzoUNzEt8DaYBg30B8Dzims8OJ5scN7UXDCdxoknJg2lzknHs+eRPy/Cs1U2ZJf8ctJuc823l/O7SROZS43Hw89JupBCStbcwC/dSn7hKf9l7Z7w2wTZeJKvmC4+kSQ+Q9Y1BJUjGdhNUAIYanxo8rdEVhOgcibnwaY7wf2udp3yhwv/muLXCqd x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: c545dc50-1393-4b6f-86ef-08d56b300924 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1090; x-ms-traffictypediagnostic: BL0PR2101MB1090: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(215639381216008)(274141268393343)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BL0PR2101MB1090;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1090; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(396003)(39380400002)(39860400002)(346002)(199004)(189003)(2900100001)(5660300001)(316002)(25786009)(4326008)(14454004)(2950100002)(478600001)(575784001)(39060400002)(107886003)(72206003)(6666003)(22452003)(10290500003)(186003)(3660700001)(86612001)(76176011)(86362001)(53936002)(3280700002)(106356001)(6436002)(6486002)(59450400001)(81166006)(81156014)(2501003)(6506007)(97736004)(26005)(7736002)(6512007)(6346003)(102836004)(105586002)(68736007)(8936002)(5250100002)(305945005)(36756003)(1076002)(6116002)(3846002)(8676002)(110136005)(66066001)(54906003)(2906002)(10090500001)(99286004)(22906009)(142933001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1090;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: w+beRF85+xHdC/avWYeBxbUjav81L+ABh6/tHe50yXdFeoMNWcByv0Ct70Nkdlg8CCATGX+92XkzWsT9xRPVQA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c545dc50-1393-4b6f-86ef-08d56b300924 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:00:36.9877 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1090 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tetsuo Handa [ Upstream commit bb422a738f6566f7439cd347d54e321e4fe92a9f ] Syzbot caught an oops at unregister_shrinker() because combination of commit 1d3d4437eae1bb29 ("vmscan: per-node deferred work") and fault injection made register_shrinker() fail and the caller of register_shrinker() did not check for failure. ---------- [ 554.881422] FAULT_INJECTION: forcing a failure. [ 554.881422] name failslab, interval 1, probability 0, space 0, times 0 [ 554.881438] CPU: 1 PID: 13231 Comm: syz-executor1 Not tainted 4.14.0-rc8= + #82 [ 554.881443] Hardware name: Google Google Compute Engine/Google Compute E= ngine, BIOS Google 01/01/2011 [ 554.881445] Call Trace: [ 554.881459] dump_stack+0x194/0x257 [ 554.881474] ? arch_local_irq_restore+0x53/0x53 [ 554.881486] ? find_held_lock+0x35/0x1d0 [ 554.881507] should_fail+0x8c0/0xa40 [ 554.881522] ? fault_create_debugfs_attr+0x1f0/0x1f0 [ 554.881537] ? check_noncircular+0x20/0x20 [ 554.881546] ? find_next_zero_bit+0x2c/0x40 [ 554.881560] ? ida_get_new_above+0x421/0x9d0 [ 554.881577] ? find_held_lock+0x35/0x1d0 [ 554.881594] ? __lock_is_held+0xb6/0x140 [ 554.881628] ? check_same_owner+0x320/0x320 [ 554.881634] ? lock_downgrade+0x990/0x990 [ 554.881649] ? find_held_lock+0x35/0x1d0 [ 554.881672] should_failslab+0xec/0x120 [ 554.881684] __kmalloc+0x63/0x760 [ 554.881692] ? lock_downgrade+0x990/0x990 [ 554.881712] ? register_shrinker+0x10e/0x2d0 [ 554.881721] ? trace_event_raw_event_module_request+0x320/0x320 [ 554.881737] register_shrinker+0x10e/0x2d0 [ 554.881747] ? prepare_kswapd_sleep+0x1f0/0x1f0 [ 554.881755] ? _down_write_nest_lock+0x120/0x120 [ 554.881765] ? memcpy+0x45/0x50 [ 554.881785] sget_userns+0xbcd/0xe20 (...snipped...) [ 554.898693] kasan: CONFIG_KASAN_INLINE enabled [ 554.898724] kasan: GPF could be caused by NULL-ptr deref or user memory = access [ 554.898732] general protection fault: 0000 [#1] SMP KASAN [ 554.898737] Dumping ftrace buffer: [ 554.898741] (ftrace buffer empty) [ 554.898743] Modules linked in: [ 554.898752] CPU: 1 PID: 13231 Comm: syz-executor1 Not tainted 4.14.0-rc8= + #82 [ 554.898755] Hardware name: Google Google Compute Engine/Google Compute E= ngine, BIOS Google 01/01/2011 [ 554.898760] task: ffff8801d1dbe5c0 task.stack: ffff8801c9e38000 [ 554.898772] RIP: 0010:__list_del_entry_valid+0x7e/0x150 [ 554.898775] RSP: 0018:ffff8801c9e3f108 EFLAGS: 00010246 [ 554.898780] RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 00000000000= 00000 [ 554.898784] RDX: 0000000000000000 RSI: ffff8801c53c6f98 RDI: ffff8801c53= c6fa0 [ 554.898788] RBP: ffff8801c9e3f120 R08: 1ffff100393c7d55 R09: 00000000000= 00004 [ 554.898791] R10: ffff8801c9e3ef70 R11: 0000000000000000 R12: 00000000000= 00000 [ 554.898795] R13: dffffc0000000000 R14: 1ffff100393c7e45 R15: ffff8801c53= c6f98 [ 554.898800] FS: 0000000000000000(0000) GS:ffff8801db300000(0000) knlGS:= 0000000000000000 [ 554.898804] CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 [ 554.898807] CR2: 00000000dbc23000 CR3: 00000001c7269000 CR4: 00000000001= 406e0 [ 554.898813] DR0: 0000000020000000 DR1: 0000000020000000 DR2: 00000000000= 00000 [ 554.898816] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 00000000000= 00600 [ 554.898818] Call Trace: [ 554.898828] unregister_shrinker+0x79/0x300 [ 554.898837] ? perf_trace_mm_vmscan_writepage+0x750/0x750 [ 554.898844] ? down_write+0x87/0x120 [ 554.898851] ? deactivate_super+0x139/0x1b0 [ 554.898857] ? down_read+0x150/0x150 [ 554.898864] ? check_same_owner+0x320/0x320 [ 554.898875] deactivate_locked_super+0x64/0xd0 [ 554.898883] deactivate_super+0x141/0x1b0 ---------- Since allowing register_shrinker() callers to call unregister_shrinker() when register_shrinker() failed can simplify error recovery path, this patch makes unregister_shrinker() no-op when register_shrinker() failed. Also, reset shrinker->nr_deferred in case unregister_shrinker() was by error called twice. Signed-off-by: Tetsuo Handa Signed-off-by: Aliaksei Karaliou Reported-by: syzbot Cc: Glauber Costa Cc: Al Viro Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index eb2f0315b8c0..441f346fb5e2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -297,10 +297,13 @@ EXPORT_SYMBOL(register_shrinker); */ void unregister_shrinker(struct shrinker *shrinker) { + if (!shrinker->nr_deferred) + return; down_write(&shrinker_rwsem); list_del(&shrinker->list); up_write(&shrinker_rwsem); kfree(shrinker->nr_deferred); + shrinker->nr_deferred =3D NULL; } EXPORT_SYMBOL(unregister_shrinker); =20 --=20 2.11.0