Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp441318pxf; Wed, 10 Mar 2021 09:11:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6rjSBNByZzqLR94wZnBrMR8wor8E2dph0z6MLQoFbXeWw6UVLIMFEP+JVuD7wKQsGF8iC X-Received: by 2002:a05:6402:b41:: with SMTP id bx1mr4542955edb.69.1615396306896; Wed, 10 Mar 2021 09:11:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615396306; cv=none; d=google.com; s=arc-20160816; b=ZpNaM6PWJYjHDCJRhXeJwkrHaByyR2q7L3ZakCtMKxmHgAB5IwMygg1DZ5kz/GcBbr CGVjBBX29oVWEOeiLtpMOXSRnaHNUR56bvCl9aOx+MTJ0nBxSi+QALOuDJ7RklIBPvXU 0TjSDrr73Acx9SqtudBW44sa9FYaKmF8jEkDKf1brpnJaXviRR9IK3KpW5njoBIAsRie 2gJC9+CGayhMLNUqpzxzvZEs8Y1cKAjPh2F0J9bPGma06Qz/0xyMA7DFbpWRdf9UR5Gt SfR0SV636kzSi3OQfI4k9W8y+BqIXwidKkYPGEpNsn4X8UEYM8MCXKeEag1ZmF5PRHSW JVOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=ta7MuXNJjVZcQim7GdxCVwX0xElPlJTwWBBVH7c0PKw=; b=LwKBHPf8LEUhmTQXhoLRNSllW0OjZGqQx7uubkZSJwkT7K+Q8KGAz8x++ZKiMw/nJm ilNU309AqCquJCLkF1ftddCGCSkDI3sZWAW7PHWrLD2ZE8Gk/0jAMOMNLmsilzwCYVH/ augtZYJYSQMwqOUK9nyQXhnbvOtD+/naChuIe4KL0hAU62UrbNdugdkxDSyWpzPvipQt JLYv60yHQpcKhfVN01oqIA8tFC7y+2eNvN8LJL1+WtD1kkg0vqb+k1IUOuIL9dvz7WjH 8hu/kR8kX79cNHYNQXSfCHQnFx0k+OhL+M17iz99iyxuDgbDB5+XnX14ji975iRy5bWo aK4w== 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=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si4387531ejc.483.2021.03.10.09.11.18; Wed, 10 Mar 2021 09:11:46 -0800 (PST) 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=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbhCJRKW (ORCPT + 99 others); Wed, 10 Mar 2021 12:10:22 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:49156 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhCJRKH (ORCPT ); Wed, 10 Mar 2021 12:10:07 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lK2LN-00E697-2Y; Wed, 10 Mar 2021 10:09:57 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=fess.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lK2LL-000QlE-92; Wed, 10 Mar 2021 10:09:56 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Filippo Sironi Cc: , , , , , , , , , , , , References: <20210310123703.27894-1-sironi@amazon.de> Date: Wed, 10 Mar 2021 11:09:58 -0600 In-Reply-To: <20210310123703.27894-1-sironi@amazon.de> (Filippo Sironi's message of "Wed, 10 Mar 2021 13:37:02 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1lK2LL-000QlE-92;;;mid=;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19mcqpwDm93cSui+dUoiUk0SpN8vkf2Q9I= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa03.xmission.com X-Spam-Level: * X-Spam-Status: No, score=1.7 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_XMDrugObfuBody_12,XMSubLong, XM_B_SpammyWords autolearn=disabled version=3.4.2 X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4999] * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa03 1397; Body=1 Fuz1=1 Fuz2=1] * 0.2 XM_B_SpammyWords One or more commonly used spammy words * 1.0 T_XMDrugObfuBody_12 obfuscated drug references X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Filippo Sironi X-Spam-Relay-Country: X-Spam-Timing: total 734 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.4 (0.5%), b_tie_ro: 2.3 (0.3%), parse: 0.95 (0.1%), extract_message_metadata: 3.3 (0.5%), get_uri_detail_list: 1.36 (0.2%), tests_pri_-1000: 4.0 (0.5%), tests_pri_-950: 1.34 (0.2%), tests_pri_-900: 1.06 (0.1%), tests_pri_-90: 119 (16.2%), check_bayes: 118 (16.0%), b_tokenize: 8 (1.1%), b_tok_get_all: 7 (1.0%), b_comp_prob: 2.3 (0.3%), b_tok_touch_all: 97 (13.2%), b_finish: 0.68 (0.1%), tests_pri_0: 585 (79.8%), check_dkim_signature: 0.40 (0.1%), check_dkim_adsp: 380 (51.8%), poll_dns_idle: 379 (51.6%), tests_pri_10: 1.60 (0.2%), tests_pri_500: 5 (0.7%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC PATCH] mm: fork: Prevent a NULL deref by getting mm only if the refcount isn't 0 X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Filippo Sironi writes: > We've seen a number of crashes with the following signature: > > BUG: kernel NULL pointer dereference, address: 0000000000000000 > #PF: supervisor read access in kernel mode > #PF: error_code(0x0000) - not-present page > ... > Oops: 0000 [#1] SMP PTI > ... > RIP: 0010:__rb_erase_color+0xc2/0x260 > ... > Call Trace: > unlink_file_vma+0x36/0x50 > free_pgtables+0x62/0x110 > exit_mmap+0xd5/0x160 > ? put_dec+0x3a/0x90 > ? num_to_str+0xa8/0xc0 > mmput+0x11/0xb0 > do_task_stat+0x940/0xc80 > proc_single_show+0x49/0x80 > ? __check_object_size+0xcc/0x1a0 > seq_read+0xd3/0x400 > vfs_read+0x72/0xb0 > ksys_read+0x9c/0xd0 > do_syscall_64+0x69/0x400 > ? schedule+0x2a/0x90 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > ... > > This happens when a process goes through the tasks stats in procfs while > another is exiting. This looks like a race where the process that's > exiting drops the last reference on the mm (with mmput) while the other > increases it (with mmget). By only increasing when the reference isn't > 0 to begin with, we prevent this from happening. For this to be a race with exit this would require racing with exit_mm where current->mm is cleared. Looking at exit_mm() the code does: struct mm_struct *mm = current->mm; mmap_read_lock(mm); mmgrab(mm); task_lock(current); local_irq_disable(); current->mm = NULL; local_irq_enable(); task_unlock(current); mmap_read_unlock(mm); mmput(mm); Which seems to guarantee "mm_users > 0" if "task->mm != NULL" under tasklist_lock. So I suggest you instrument your failing kernels and find what is improperly decrementing mm_users. Eric