Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2463113imm; Mon, 24 Sep 2018 04:57:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV63jxb1kU2FtVuSPjCCr/KzBfaHm3sWdlxjfvhIx2LSzH433Nq+BMXAxdYIiRZJLzC4NUgAE X-Received: by 2002:a17:902:6501:: with SMTP id b1-v6mr10428179plk.31.1537790273434; Mon, 24 Sep 2018 04:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537790273; cv=none; d=google.com; s=arc-20160816; b=Ilg+2Ln9qsXDQqmQYb2Ps4Qi43UEGVP/pk/YxvX6xKw3VhBmssBNoV7gF594UssnMc kzX9CdOt/zXEr13jAPcguomzdu0vIbAeAvhBzzDL9YTfnnlO3HcGKZ3Kf38bNUPs3OlU 7eNi9poJ10bwRpXK8GdB9qrzAedPz83icgDLCn5rSTwpTfO1GfT1j+L6r72mVJTU6Cfv xRKyeMInStQzWKYOthHzzMl/I/QuH44v3sjlaXxdn8RAPKlmKc8FGGgCOTuO7GFOSynd U39B55fvmmbnjRs2kcUyC5M8KC+WcnozcnhxxzhelePYht6akPrLUE8aek5ZgkmSJ7D4 WFVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=WkDvnyU5Ywx2RmXHOmMzWVhPdKY51afjazJDDuPSVrg=; b=CjsEAUYvk+YgIM7771cX41b1KcXZ0Ehb/Dw1R4RI+idvtqgFhdvb71V07SEiveuucT eqdJgtgw8HOGvM8cRHTDIe6UwcNYpkraZ74juc4uCLMPXL29g3M0uXB+TtHqN91vCQ4N ngVGh1seDeGgDVTvNHah/4QWr8Bfp5M4gqldin4RhJjBMKFVPKTNQEvyC/uA8rK0+LPr Fz+JO3YR0SYqL3Vqg5BDmdGUaN3XJXha6zOkDH9qy3r+yXx1Xel3Wi0L0pOpBfHwEyeQ f3fLraDPylmn91BgNipQS/+K0oVWtyeVq0fxfnHMlAkoGySdbD+/ggOcTxoyO3trwwf1 nzHg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p185-v6si33884687pgp.504.2018.09.24.04.57.38; Mon, 24 Sep 2018 04:57:53 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730076AbeIXR6Z (ORCPT + 99 others); Mon, 24 Sep 2018 13:58:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52050 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728425AbeIXR6Z (ORCPT ); Mon, 24 Sep 2018 13:58:25 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 633141072; Mon, 24 Sep 2018 11:56:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ronny Chevalier , Richard Guy Briggs , Paul Moore , Sasha Levin Subject: [PATCH 4.4 48/70] audit: fix use-after-free in audit_add_watch Date: Mon, 24 Sep 2018 13:52:47 +0200 Message-Id: <20180924113105.389894518@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113058.420454070@linuxfoundation.org> References: <20180924113058.420454070@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ronny Chevalier [ Upstream commit baa2a4fdd525c8c4b0f704d20457195b29437839 ] audit_add_watch stores locally krule->watch without taking a reference on watch. Then, it calls audit_add_to_parent, and uses the watch stored locally. Unfortunately, it is possible that audit_add_to_parent updates krule->watch. When it happens, it also drops a reference of watch which could free the watch. How to reproduce (with KASAN enabled): auditctl -w /etc/passwd -F success=0 -k test_passwd auditctl -w /etc/passwd -F success=1 -k test_passwd2 The second call to auditctl triggers the use-after-free, because audit_to_parent updates krule->watch to use a previous existing watch and drops the reference to the newly created watch. To fix the issue, we grab a reference of watch and we release it at the end of the function. Signed-off-by: Ronny Chevalier Reviewed-by: Richard Guy Briggs Signed-off-by: Paul Moore Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/audit_watch.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -419,6 +419,13 @@ int audit_add_watch(struct audit_krule * struct path parent_path; int h, ret = 0; + /* + * When we will be calling audit_add_to_parent, krule->watch might have + * been updated and watch might have been freed. + * So we need to keep a reference of watch. + */ + audit_get_watch(watch); + mutex_unlock(&audit_filter_mutex); /* Avoid calling path_lookup under audit_filter_mutex. */ @@ -427,8 +434,10 @@ int audit_add_watch(struct audit_krule * /* caller expects mutex locked */ mutex_lock(&audit_filter_mutex); - if (ret) + if (ret) { + audit_put_watch(watch); return ret; + } /* either find an old parent or attach a new one */ parent = audit_find_parent(d_backing_inode(parent_path.dentry)); @@ -446,6 +455,7 @@ int audit_add_watch(struct audit_krule * *list = &audit_inode_hash[h]; error: path_put(&parent_path); + audit_put_watch(watch); return ret; }