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=-6.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 A1584C43331 for ; Thu, 2 Apr 2020 13:28:25 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58FFD20757 for ; Thu, 2 Apr 2020 13:28:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VEA90JV5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58FFD20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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=1585834103; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ImDeV8ChCNIsIC//JOZRqjxMb9scmdy5tvJDNDsihvs=; b=VEA90JV5JIYQ9RyuIpeKwyLrXIGAPlkjj7GTbk5mz1KLjGoi3Pq0kjttz9052/90s8ypab hupPkG4kSgxsOiro1s30BSYy4Ug3IocsVzCwXZvFIM9pZdanHveVshTALqzJWPfBo7ulRT Ezjc899udazd8eFDTYdNPU++jlFn3Bo= 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-392-M_7-S4scNQm1pgkgq7vmYQ-1; Thu, 02 Apr 2020 09:28:18 -0400 X-MC-Unique: M_7-S4scNQm1pgkgq7vmYQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13567DBA9; Thu, 2 Apr 2020 13:28:15 +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 D82FC5D9C9; Thu, 2 Apr 2020 13:28:14 +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 4913118089CE; Thu, 2 Apr 2020 13:28:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0325vbJa032118 for ; Thu, 2 Apr 2020 01:57:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B97710054E4; Thu, 2 Apr 2020 05:57:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 671CF10054E9 for ; Thu, 2 Apr 2020 05:57:36 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 C71698F843B for ; Thu, 2 Apr 2020 05:57:36 +0000 (UTC) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-vSgRgad7PrOtw8qKhkzqmQ-1; Thu, 02 Apr 2020 01:57:34 -0400 X-MC-Unique: vSgRgad7PrOtw8qKhkzqmQ-1 Received: by mail-pl1-f194.google.com with SMTP id h11so926078plr.11; Wed, 01 Apr 2020 22:57:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6dJnmRISnXhx/tid8L3bkFndKLLLawXzGhi1aYEmqBI=; b=TdzYV1izf8OG+uyiYkBOVnMsBL+3+4I5wTW5CJhMbBp12oEW9ulRmPxNEr/2Kb05hq 67ju1paAjUHTOL/JW++oYSy+jzgDV7F3brP8IuKSqxfHzQxBmN+usBOetiU+rKQI8z6M aX6ySHNPQNuBJ/QXcM4riStz6rZoGcZTt2tQ+mghN1p2aZOKPE/2djOU/3mObnlIJv/n 3hIiBX79EwEfHJEfIDywwVZAnwt4OQURAG+30pV0pS1oB4BrQPh/B14qTRJQ3z2STQau hCh6+NfX5V9NrTCgnJpw/NxZTo/uaahkoYBxEU0rxYWvTIIb0XmEuTMtlJGYh3qLvoaS ND8A== X-Gm-Message-State: AGi0PubWAuPRaFnqV7km/G8+RzOtterjgoTWzOZWB9xvhGk3thc/wPER 2cQNKRYZSqZlbUg0JgSC9cIDHF2KL3s= X-Google-Smtp-Source: APiQypKKpM2RNoBega/Jw427Lig/OopGc2RCcaSq/EMKfefz7KImd2eIOeKFi0eJjpW3VBuddiq5SA== X-Received: by 2002:a17:902:e788:: with SMTP id cp8mr1382631plb.343.1585807053025; Wed, 01 Apr 2020 22:57:33 -0700 (PDT) Received: from localhost.localdomain ([103.87.57.161]) by smtp.googlemail.com with ESMTPSA id 207sm2776058pgg.19.2020.04.01.22.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 22:57:32 -0700 (PDT) From: Amol Grover To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , James Morris , Thomas Gleixner , Peter Zijlstra , Jann Horn , David Howells , Shakeel Butt , "Eric W . Biederman" , Andrew Morton , Paul Moore , Eric Paris Subject: [PATCH 3/3 RESEND] auditsc: Do not use RCU primitive to read from cred pointer Date: Thu, 2 Apr 2020 11:26:40 +0530 Message-Id: <20200402055640.6677-3-frextrite@gmail.com> In-Reply-To: <20200402055640.6677-1-frextrite@gmail.com> References: <20200402055640.6677-1-frextrite@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0325vbJa032118 X-loop: linux-audit@redhat.com X-Mailman-Approved-At: Thu, 02 Apr 2020 09:28:10 -0400 Cc: "Paul E . McKenney" , Amol Grover , linux-kernel@vger.kernel.org, Madhuparna Bhowmik , linux-audit@redhat.com, Joel Fernandes , linux-kernel-mentees@lists.linuxfoundation.org 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.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit task_struct::cred is only used task-synchronously and does not require any RCU locks, hence, rcu_dereference_check is not required to read from it. Suggested-by: Jann Horn Co-developed-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) Signed-off-by: Amol Grover --- kernel/auditsc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 4effe01ebbe2..d3510513cdd1 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -430,24 +430,19 @@ static int audit_field_compare(struct task_struct *tsk, /* Determine if any context name data matches a rule's watch data */ /* Compare a task_struct with an audit_rule. Return 1 on match, 0 * otherwise. - * - * If task_creation is true, this is an explicit indication that we are - * filtering a task rule at task creation time. This and tsk == current are - * the only situations where tsk->cred may be accessed without an rcu read lock. */ static int audit_filter_rules(struct task_struct *tsk, struct audit_krule *rule, struct audit_context *ctx, struct audit_names *name, - enum audit_state *state, - bool task_creation) + enum audit_state *state) { const struct cred *cred; int i, need_sid = 1; u32 sid; unsigned int sessionid; - cred = rcu_dereference_check(tsk->cred, tsk == current || task_creation); + cred = tsk->cred; for (i = 0; i < rule->field_count; i++) { struct audit_field *f = &rule->fields[i]; @@ -745,7 +740,7 @@ static enum audit_state audit_filter_task(struct task_struct *tsk, char **key) rcu_read_lock(); list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) { if (audit_filter_rules(tsk, &e->rule, NULL, NULL, - &state, true)) { + &state)) { if (state == AUDIT_RECORD_CONTEXT) *key = kstrdup(e->rule.filterkey, GFP_ATOMIC); rcu_read_unlock(); @@ -791,7 +786,7 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk, list_for_each_entry_rcu(e, list, list) { if (audit_in_mask(&e->rule, ctx->major) && audit_filter_rules(tsk, &e->rule, ctx, NULL, - &state, false)) { + &state)) { rcu_read_unlock(); ctx->current_state = state; return state; @@ -815,7 +810,7 @@ static int audit_filter_inode_name(struct task_struct *tsk, list_for_each_entry_rcu(e, list, list) { if (audit_in_mask(&e->rule, ctx->major) && - audit_filter_rules(tsk, &e->rule, ctx, n, &state, false)) { + audit_filter_rules(tsk, &e->rule, ctx, n, &state)) { ctx->current_state = state; return 1; } -- 2.24.1 -- Linux-audit mailing list Linux-audit@redhat.com https://www.redhat.com/mailman/listinfo/linux-audit 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=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 7BCC8C43331 for ; Thu, 2 Apr 2020 05:57:35 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4B8312078E for ; Thu, 2 Apr 2020 05:57:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F5ZgPkj4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B8312078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 1C67186C0E; Thu, 2 Apr 2020 05:57:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KPhrXaSfpo2s; Thu, 2 Apr 2020 05:57:34 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id A1868868D8; Thu, 2 Apr 2020 05:57:34 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 90EA0C1AE2; Thu, 2 Apr 2020 05:57:34 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 00B01C07FF for ; Thu, 2 Apr 2020 05:57:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id EA8BD86C0E for ; Thu, 2 Apr 2020 05:57:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1Yvc1xmDW9rl for ; Thu, 2 Apr 2020 05:57:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by whitealder.osuosl.org (Postfix) with ESMTPS id 6E593868D8 for ; Thu, 2 Apr 2020 05:57:33 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id w9so1118118pjh.1 for ; Wed, 01 Apr 2020 22:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6dJnmRISnXhx/tid8L3bkFndKLLLawXzGhi1aYEmqBI=; b=F5ZgPkj4Jqb8jVfvdsxgqgz1JEo/1oI1a8uoJIAQA0lpNWQHcaE8671FBeypM6kX3E Dt2Vs0xHlYHGmQ8yuRM5u0mTovkVC35KiwjAZfihtabHL7dVwoUYBEe9WW4k/SUjsCFs dRRQL/gps9M5cE/BlrvUTtv8cJeWUwUo53YE3Z3r/n7QMlw59odA1tKMNrlMWSXK6ZTR ByY4qGARizvkaiTkQKjZYorE1SeoyEYKhPVCEMPxGo5R4YSnUW97n57U6H0RItQxNBga X9n5ayS/XEnySMr0+fxqtf7pACtsK5A1ad9y5KjvXkFlCFVBuCY+Vj867Hd4YWqJ8zT2 qHIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6dJnmRISnXhx/tid8L3bkFndKLLLawXzGhi1aYEmqBI=; b=fSELpu5OkjsXUCMKfFBnLReBQK1KWOrGuv0ERGf3z632yHYVtQBOUTt9djy0Z/aerd 8zf2c1SBNnFizMTLAEnrO7wTsraL0X6yA0rvQwqxs45m6X9Xy9a8U7L9SiOk0u5A51Vl eU33AKqXDC2Ty3gcQSc8u9gjpqAhrsUXbgreOhYZ5CPHKoKkW8p+KPbR1FBCaUJLryuC //r5Mv82NzXufzr9wWKfIvzXTOiO5aw6ZzOvvgVC/xeLwLOaYw7DqwGF4p3nAzbYo46X 1uYvQ85pHnPH9xD1Zhccx7PH61B+CmyHUfxW4IYvjeb5Jbj2n+u+MT2EHVvrVDjNYicq RmFw== X-Gm-Message-State: AGi0PubwUwcrPt60rsDR6ETxa42uRJI52z469nnfL6SMXS+RI2310Mha ZytmumgRj2sgrPpQP7RPRUM= X-Google-Smtp-Source: APiQypKKpM2RNoBega/Jw427Lig/OopGc2RCcaSq/EMKfefz7KImd2eIOeKFi0eJjpW3VBuddiq5SA== X-Received: by 2002:a17:902:e788:: with SMTP id cp8mr1382631plb.343.1585807053025; Wed, 01 Apr 2020 22:57:33 -0700 (PDT) Received: from localhost.localdomain ([103.87.57.161]) by smtp.googlemail.com with ESMTPSA id 207sm2776058pgg.19.2020.04.01.22.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 22:57:32 -0700 (PDT) From: Amol Grover To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , James Morris , Thomas Gleixner , Peter Zijlstra , Jann Horn , David Howells , Shakeel Butt , "Eric W . Biederman" , Andrew Morton , Paul Moore ,Eric Paris Date: Thu, 2 Apr 2020 11:26:40 +0530 Message-Id: <20200402055640.6677-3-frextrite@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200402055640.6677-1-frextrite@gmail.com> References: <20200402055640.6677-1-frextrite@gmail.com> MIME-Version: 1.0 Cc: "Paul E . McKenney" , linux-kernel@vger.kernel.org, Madhuparna Bhowmik , linux-audit@redhat.com, Joel Fernandes , linux-kernel-mentees@lists.linuxfoundation.org Subject: [Linux-kernel-mentees] [PATCH 3/3 RESEND] auditsc: Do not use RCU primitive to read from cred pointer X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" task_struct::cred is only used task-synchronously and does not require any RCU locks, hence, rcu_dereference_check is not required to read from it. Suggested-by: Jann Horn Co-developed-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) Signed-off-by: Amol Grover --- kernel/auditsc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 4effe01ebbe2..d3510513cdd1 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -430,24 +430,19 @@ static int audit_field_compare(struct task_struct *tsk, /* Determine if any context name data matches a rule's watch data */ /* Compare a task_struct with an audit_rule. Return 1 on match, 0 * otherwise. - * - * If task_creation is true, this is an explicit indication that we are - * filtering a task rule at task creation time. This and tsk == current are - * the only situations where tsk->cred may be accessed without an rcu read lock. */ static int audit_filter_rules(struct task_struct *tsk, struct audit_krule *rule, struct audit_context *ctx, struct audit_names *name, - enum audit_state *state, - bool task_creation) + enum audit_state *state) { const struct cred *cred; int i, need_sid = 1; u32 sid; unsigned int sessionid; - cred = rcu_dereference_check(tsk->cred, tsk == current || task_creation); + cred = tsk->cred; for (i = 0; i < rule->field_count; i++) { struct audit_field *f = &rule->fields[i]; @@ -745,7 +740,7 @@ static enum audit_state audit_filter_task(struct task_struct *tsk, char **key) rcu_read_lock(); list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) { if (audit_filter_rules(tsk, &e->rule, NULL, NULL, - &state, true)) { + &state)) { if (state == AUDIT_RECORD_CONTEXT) *key = kstrdup(e->rule.filterkey, GFP_ATOMIC); rcu_read_unlock(); @@ -791,7 +786,7 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk, list_for_each_entry_rcu(e, list, list) { if (audit_in_mask(&e->rule, ctx->major) && audit_filter_rules(tsk, &e->rule, ctx, NULL, - &state, false)) { + &state)) { rcu_read_unlock(); ctx->current_state = state; return state; @@ -815,7 +810,7 @@ static int audit_filter_inode_name(struct task_struct *tsk, list_for_each_entry_rcu(e, list, list) { if (audit_in_mask(&e->rule, ctx->major) && - audit_filter_rules(tsk, &e->rule, ctx, n, &state, false)) { + audit_filter_rules(tsk, &e->rule, ctx, n, &state)) { ctx->current_state = state; return 1; } -- 2.24.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees 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=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 1BC91C10F26 for ; Thu, 2 Apr 2020 05:57:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E65442078E for ; Thu, 2 Apr 2020 05:57:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F5ZgPkj4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729103AbgDBF5e (ORCPT ); Thu, 2 Apr 2020 01:57:34 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40767 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbgDBF5e (ORCPT ); Thu, 2 Apr 2020 01:57:34 -0400 Received: by mail-pl1-f193.google.com with SMTP id h11so937171plk.7 for ; Wed, 01 Apr 2020 22:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6dJnmRISnXhx/tid8L3bkFndKLLLawXzGhi1aYEmqBI=; b=F5ZgPkj4Jqb8jVfvdsxgqgz1JEo/1oI1a8uoJIAQA0lpNWQHcaE8671FBeypM6kX3E Dt2Vs0xHlYHGmQ8yuRM5u0mTovkVC35KiwjAZfihtabHL7dVwoUYBEe9WW4k/SUjsCFs dRRQL/gps9M5cE/BlrvUTtv8cJeWUwUo53YE3Z3r/n7QMlw59odA1tKMNrlMWSXK6ZTR ByY4qGARizvkaiTkQKjZYorE1SeoyEYKhPVCEMPxGo5R4YSnUW97n57U6H0RItQxNBga X9n5ayS/XEnySMr0+fxqtf7pACtsK5A1ad9y5KjvXkFlCFVBuCY+Vj867Hd4YWqJ8zT2 qHIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6dJnmRISnXhx/tid8L3bkFndKLLLawXzGhi1aYEmqBI=; b=qrBCXPpsktzomxXkvkqX75OHK9hWb0HbzVtaNkZ08Kx/09yP26wVzgAeykvI8QUqx6 XucsU6u7GRo2rVUGeQklcWJZoKX2bD9LC7IsA/VzEl7q2kr8JCuTxuDDqYjD2OwFz3Ci f9s5bVcerGgrAUTgUrkbVvnfm2aqHNvvdiBzXbtrBYgwI+YR2RU8ysAM9BJNc5HFdQbl /LhLvG83QVxqHuzYNrQukwWFc43F76v55GJu7Gn+V19azjlvUvyMeMNXOgFFX3PVBZKR QbHMOkHIrBWvHxm2nwqpoLjzNtrvt2dpPusVam8xjwlyrYoer87izapfRBTjToUqiwH1 B7nA== X-Gm-Message-State: AGi0PuZPHHOVQdvFGVck3tV+9K+hsm4TCalXtf03UaJ1ox3q7zLszua7 bHmwV9dc3yJvxm7EpuGg41HXu1HMN/U= X-Google-Smtp-Source: APiQypKKpM2RNoBega/Jw427Lig/OopGc2RCcaSq/EMKfefz7KImd2eIOeKFi0eJjpW3VBuddiq5SA== X-Received: by 2002:a17:902:e788:: with SMTP id cp8mr1382631plb.343.1585807053025; Wed, 01 Apr 2020 22:57:33 -0700 (PDT) Received: from localhost.localdomain ([103.87.57.161]) by smtp.googlemail.com with ESMTPSA id 207sm2776058pgg.19.2020.04.01.22.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 22:57:32 -0700 (PDT) From: Amol Grover To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , James Morris , Thomas Gleixner , Peter Zijlstra , Jann Horn , David Howells , Shakeel Butt , "Eric W . Biederman" , Andrew Morton , Paul Moore , Eric Paris Cc: linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, linux-audit@redhat.com, Joel Fernandes , Madhuparna Bhowmik , "Paul E . McKenney" , Amol Grover Subject: [PATCH 3/3 RESEND] auditsc: Do not use RCU primitive to read from cred pointer Date: Thu, 2 Apr 2020 11:26:40 +0530 Message-Id: <20200402055640.6677-3-frextrite@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200402055640.6677-1-frextrite@gmail.com> References: <20200402055640.6677-1-frextrite@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org task_struct::cred is only used task-synchronously and does not require any RCU locks, hence, rcu_dereference_check is not required to read from it. Suggested-by: Jann Horn Co-developed-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) Signed-off-by: Amol Grover --- kernel/auditsc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 4effe01ebbe2..d3510513cdd1 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -430,24 +430,19 @@ static int audit_field_compare(struct task_struct *tsk, /* Determine if any context name data matches a rule's watch data */ /* Compare a task_struct with an audit_rule. Return 1 on match, 0 * otherwise. - * - * If task_creation is true, this is an explicit indication that we are - * filtering a task rule at task creation time. This and tsk == current are - * the only situations where tsk->cred may be accessed without an rcu read lock. */ static int audit_filter_rules(struct task_struct *tsk, struct audit_krule *rule, struct audit_context *ctx, struct audit_names *name, - enum audit_state *state, - bool task_creation) + enum audit_state *state) { const struct cred *cred; int i, need_sid = 1; u32 sid; unsigned int sessionid; - cred = rcu_dereference_check(tsk->cred, tsk == current || task_creation); + cred = tsk->cred; for (i = 0; i < rule->field_count; i++) { struct audit_field *f = &rule->fields[i]; @@ -745,7 +740,7 @@ static enum audit_state audit_filter_task(struct task_struct *tsk, char **key) rcu_read_lock(); list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) { if (audit_filter_rules(tsk, &e->rule, NULL, NULL, - &state, true)) { + &state)) { if (state == AUDIT_RECORD_CONTEXT) *key = kstrdup(e->rule.filterkey, GFP_ATOMIC); rcu_read_unlock(); @@ -791,7 +786,7 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk, list_for_each_entry_rcu(e, list, list) { if (audit_in_mask(&e->rule, ctx->major) && audit_filter_rules(tsk, &e->rule, ctx, NULL, - &state, false)) { + &state)) { rcu_read_unlock(); ctx->current_state = state; return state; @@ -815,7 +810,7 @@ static int audit_filter_inode_name(struct task_struct *tsk, list_for_each_entry_rcu(e, list, list) { if (audit_in_mask(&e->rule, ctx->major) && - audit_filter_rules(tsk, &e->rule, ctx, n, &state, false)) { + audit_filter_rules(tsk, &e->rule, ctx, n, &state)) { ctx->current_state = state; return 1; } -- 2.24.1