Received: by 10.223.185.116 with SMTP id b49csp1335959wrg; Wed, 21 Feb 2018 17:00:48 -0800 (PST) X-Google-Smtp-Source: AH8x226gmvVwKxOgvFuoA5dA4dylFBcbNgSJFIdoFqMYSenQ1zoP3ts7MuoGqqGc2i1yoIKc4FUI X-Received: by 10.101.81.12 with SMTP id f12mr4112589pgq.81.1519261248008; Wed, 21 Feb 2018 17:00:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519261247; cv=none; d=google.com; s=arc-20160816; b=pMsKuod9ftSkG8nqAaoOAfxK6NbjmfJZZ6jF37nOT8w1THauOkUHZ8xdJOiBTU1P7n cJhxfifPq+oDbomTbd0E3V/PRNnVtjnVbpKjqzA6uGOi/6KWOI/DcojL+Gx7uAm5pnBp uiocIEEqD+V6ZP3RDaZZT0YgfADyn8diA9qY4hq9R+BvQC0LA0/oqjD3QYvCenmHzsqJ c4WAKhZfSqze45OFuZCjbH7CJRrTuMGritfaPkoO8a0rYhUSR4nyHztcF7cXOs0wBZYf 1ErtmFbogkAiKRCAIqizIGfmWuzKTkXp8gjFwaEWY8t3MLu1l3aKKr6O0EU84aUGzPFX kLiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=zVMR/b58UMm9i6CIWWw4SqmA5ALeifwjQQ2bFaw/S+w=; b=vL4s9faPoOD5xDH8szRad9+ATnbsmKXMGXWj1JaF2N62F6YeYFbL69tXwkkY9/Qa8l vJapMFu8vsIMH4rFDrhJTdRtYrGOYUrlcQ36clD5hi/pOzdBr8FUlXSEaQCUD0LD2UPx Ca5Mqg0qtEoVnWzBcjhC0iXRINKWczNl8lZ7P69Ey/JaIcHc47gdI15d6YHQLYGa/bz8 f8hoI3gIgpe5nX/tTHtLH0Ce635lB3fmYVlCPryAO4Yee5QBroh4h/WBoLFb6UKsNvId zku01fEOpAIEkqXOg95gGVXr0LxvyNchXBDIybJAwnQckJlLJoV+RLvT/yoQwgFGYyHv GJuQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si8080559pfm.325.2018.02.21.17.00.33; Wed, 21 Feb 2018 17:00:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751602AbeBVA7y (ORCPT + 99 others); Wed, 21 Feb 2018 19:59:54 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33336 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751423AbeBVA7x (ORCPT ); Wed, 21 Feb 2018 19:59:53 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 160E68D6D0; Thu, 22 Feb 2018 00:59:53 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-12.rdu2.redhat.com [10.10.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2AB22024CA9; Thu, 22 Feb 2018 00:59:51 +0000 (UTC) Date: Wed, 21 Feb 2018 19:55:49 -0500 From: Richard Guy Briggs To: Paul Moore Cc: Linux-Audit Mailing List , LKML , Eric Paris , Steve Grubb Subject: Re: [PATCH] audit: return on memory error to avoid null pointer dereference Message-ID: <20180222005549.m45nkj5n6wbshbdl@madcap2.tricolour.ca> References: <2000f6951431b4f19947d7aa41bb8efd2fe3f15b.1519196084.git.rgb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171027 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 22 Feb 2018 00:59:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 22 Feb 2018 00:59:53 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rgb@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-02-21 19:02, Paul Moore wrote: > On Wed, Feb 21, 2018 at 6:49 PM, Paul Moore wrote: > > On Wed, Feb 21, 2018 at 4:30 AM, Richard Guy Briggs wrote: > >> If there is a memory allocation error when trying to change an audit > >> kernel feature value, the ignored allocation error will trigger a NULL > >> pointer dereference oops on subsequent use of that pointer. Return > >> instead. > >> > >> Passes audit-testsuite. > >> See: https://github.com/linux-audit/audit-kernel/issues/76 > >> Signed-off-by: Richard Guy Briggs > >> --- > >> kernel/audit.c | 2 ++ > >> 1 file changed, 2 insertions(+) > > > > Thanks, merged. > > > > In the future a "[PATCH v2]" prefix would be appreciated for patches > > like this, it makes things a little easier in my inbox. (Sorry, forgot in haste to get that fixed one out...) > After merging this I went through all the other callers to see if they > suffered the same mistake and everyone except for IMA was checking the > returned pointer for NULL. Upon looking at the IMA code, and the > audit code which is called, I realized we are actually "ok" as > audit_log_task_info(), audit_log_format(), audit_log_end(), and others > all check for a NULL audit_buffer at the very top of the functions. > I'm going to leave this patch merged, it's a good practice after all, > but I don't believe that unpatched systems are in any danger of > oops'ing here. On review, agreed. My ctags/cscope DBs need regeneration, so I hadn't noticed that the functions to which I was led weren't the ones I was seeking, and while these three do check, not all functions that accept a struct audit_buffer pointer parameter don't check for NULL. Now that I check, I only find audit_expand (whose callers are all protected) and audit_log_d_path (whose callers all appear to be protected), the latter of which I've spent a bit of time staring at of late (ghak8, ghak21...). We're ok. > >> diff --git a/kernel/audit.c b/kernel/audit.c > >> index 5c25449..2de74be 100644 > >> --- a/kernel/audit.c > >> +++ b/kernel/audit.c > >> @@ -1059,6 +1059,8 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature > >> return; > >> > >> ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_FEATURE_CHANGE); > >> + if (!ab) > >> + return; > >> audit_log_task_info(ab, current); > >> audit_log_format(ab, " feature=%s old=%u new=%u old_lock=%u new_lock=%u res=%d", > >> audit_feature_names[which], !!old_feature, !!new_feature, > >> -- > >> 1.8.3.1 > > -- > paul moore > www.paul-moore.com - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635