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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 C71A9C55185 for ; Wed, 22 Apr 2020 12:25:37 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79E7A208E4 for ; Wed, 22 Apr 2020 12:25:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LpBR4mXK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79E7A208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-audit-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587558336; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GVgQx7Tr9/ANtpOF4t3IUkjg4lbGxA/HJy2aHAbuLGA=; b=LpBR4mXKBc+OeqttdIrxwy/Orx0gRY3FOexeQvkCRvOJc5z6bVx9lkNzD9tjkKzvGOcFLW /bslNZxWCUHIVHbl4eZxe/I4r9OvPlqjBaIZUd1v4RiOQZENj16nC2ghrFjWDXrOb7L4zd CtJeDOm7UehTEaQ4vgyhBNJB2YE+1dM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-90-WfM9SlLBPFCXAFI8LZdRSg-1; Wed, 22 Apr 2020 08:25:34 -0400 X-MC-Unique: WfM9SlLBPFCXAFI8LZdRSg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31204801E7A; Wed, 22 Apr 2020 12:25:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 026FF600E7; Wed, 22 Apr 2020 12:25:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 811C41809541; Wed, 22 Apr 2020 12:25:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03M6Shpl008304 for ; Wed, 22 Apr 2020 02:28:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EA6C2026D66; Wed, 22 Apr 2020 06:28:43 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 397C12026D68 for ; Wed, 22 Apr 2020 06:28:41 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4FD4C101A55A for ; Wed, 22 Apr 2020 06:28:41 +0000 (UTC) Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-cXFIE08hNBi_MTG_2PyaCA-1; Wed, 22 Apr 2020 02:28:38 -0400 X-MC-Unique: cXFIE08hNBi_MTG_2PyaCA-1 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 9DED9989F944452239E9; Wed, 22 Apr 2020 14:28:34 +0800 (CST) Received: from DESKTOP-KBFSBNP.china.huawei.com (10.67.101.172) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Wed, 22 Apr 2020 14:28:28 +0800 From: Yiwen Gu To: , Subject: [PATCH] audit: allow audit_reusename to check kernel path Date: Wed, 22 Apr 2020 14:28:27 +0800 Message-ID: <1587536907-63272-1-git-send-email-guyiwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.101.172] X-CFilter-Loop: Reflected X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03M6Shpl008304 X-loop: linux-audit@redhat.com X-Mailman-Approved-At: Wed, 22 Apr 2020 08:24:52 -0400 Cc: linux-audit@redhat.com X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Currently, audit_reusename check file path only by comparing userspace pointer "uptr", without checking the situation where the file name is different with the same uptr. Add kname into audit_reusename function to check file names from the audit_names list. Signed-off-by: Yiwen Gu --- fs/namei.c | 9 +++++---- include/linux/audit.h | 11 +++++++---- kernel/auditsc.c | 7 ++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index db6565c99825..d5fb4bd12aec 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -128,13 +128,10 @@ struct filename * getname_flags(const char __user *filename, int flags, int *empty) { struct filename *result; + struct filename *result_audit; char *kname; int len; - result = audit_reusename(filename); - if (result) - return result; - result = __getname(); if (unlikely(!result)) return ERR_PTR(-ENOMEM); @@ -197,6 +194,10 @@ getname_flags(const char __user *filename, int flags, int *empty) } } + result_audit = audit_reusename(filename, kname); + if (result_audit) + return result_audit; + result->uptr = filename; result->aname = NULL; audit_getname(result); diff --git a/include/linux/audit.h b/include/linux/audit.h index f9ceae57ca8d..71fb783f14c4 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -266,7 +266,8 @@ extern void __audit_free(struct task_struct *task); extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3); extern void __audit_syscall_exit(int ret_success, long ret_value); -extern struct filename *__audit_reusename(const __user char *uptr); +extern struct filename *__audit_reusename(const __user char *uptr, + const char *kname); extern void __audit_getname(struct filename *name); extern void __audit_inode(struct filename *name, const struct dentry *dentry, @@ -316,10 +317,11 @@ static inline void audit_syscall_exit(void *pt_regs) __audit_syscall_exit(success, return_code); } } -static inline struct filename *audit_reusename(const __user char *name) +static inline struct filename *audit_reusename(const __user char *name, + const char *kname) { if (unlikely(!audit_dummy_context())) - return __audit_reusename(name); + return __audit_reusename(name, kname); return NULL; } static inline void audit_getname(struct filename *name) @@ -539,7 +541,8 @@ static inline struct audit_context *audit_context(void) { return NULL; } -static inline struct filename *audit_reusename(const __user char *name) +static inline struct filename *audit_reusename(const __user char *name, + const char *kname) { return NULL; } diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 4effe01ebbe2..62ffc02abb98 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1843,13 +1843,14 @@ static struct audit_names *audit_alloc_name(struct audit_context *context, /** * __audit_reusename - fill out filename with info from existing entry * @uptr: userland ptr to pathname + * @kname: kernel pathname string * * Search the audit_names list for the current audit context. If there is an - * existing entry with a matching "uptr" then return the filename + * existing entry with matching "uptr" and "kname" then return the filename * associated with that audit_name. If not, return NULL. */ struct filename * -__audit_reusename(const __user char *uptr) +__audit_reusename(const __user char *uptr, const char *kname) { struct audit_context *context = audit_context(); struct audit_names *n; @@ -1857,7 +1858,7 @@ __audit_reusename(const __user char *uptr) list_for_each_entry(n, &context->names_list, list) { if (!n->name) continue; - if (n->name->uptr == uptr) { + if (n->name->uptr == uptr && !strcmp(kname, n->name->name)) { n->name->refcnt++; return n->name; } -- 2.17.1 -- Linux-audit mailing list Linux-audit@redhat.com https://www.redhat.com/mailman/listinfo/linux-audit