Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6601947imm; Mon, 23 Jul 2018 23:00:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfEAEyQzHtIoo8fNCdL/HRyMtbLI+ldhXePfyWwhNzlW67La19SiVeOW9ck6iP4zb2vxOBa X-Received: by 2002:a17:902:142:: with SMTP id 60-v6mr13766423plb.330.1532412028822; Mon, 23 Jul 2018 23:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532412028; cv=none; d=google.com; s=arc-20160816; b=I9h2+TBajWACVUSC0yXeohR3HWQQB4Bho+EWd+CCfyiQwrdOYzJ+YDUW+xWfPsTWyG bp3KM+JD996TpDH65+9zWcw0O1+JDS2e0WTAo2FIWGa3HfT7cksjSojs006fVEZdDX5l A6D53C1x2p/jo8i3FMLledqSDvFBKfiOwJN1JDLboGepXs/LCffqAoydfRCz2neevM3P 0S/r0cboiRl8CQe9fj1aTFDTFGLW1THNRJ8KEciZCSZYvIm4Mjc3uThmJfurqOK8xQmY WQDriml8lg1HlQDZlU6Aj47j+mhShkZcahd8Z6dHP2dswgLWMD3zAoBdM4hqW8nsgu1m 1cYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yl30+CIRjdlbTv8AuFmLJK4zVyQrcGKZq6s8aDPz7c8=; b=UpWrQbfGW11lCU0DZ+nmspWIBEOKy+IMgZ1e22jA67mP9ejSUSTvoyNxYsC3TaCO9i thUaxCOwgspAeKdCb2amGU0Pt1+Ynrxsudc8NaSmS9/14rkueQc0lLLsuuRHGI4i9FxJ ad6i1xplFUKAzxInTVPNq75XR4u66GVb76PCO3vdcFl1NpXnmrmk28LUYdVKy2i1FHGo yPw4HqtHaUiqPCmMUD7dTyw4zW4YrkM72lOD0XLy+ViUWoJPWYgKAdwHHCg6yj2g6xxO USQCdlVEkCSHtMlg/ih3/Xx0FVKSlAd1vLj/e4B+DC8bTyWYDNnMmcUqYBQNDfVUGuoy KqRw== 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 31-v6si9756318pla.155.2018.07.23.23.00.13; Mon, 23 Jul 2018 23:00:28 -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 S2388256AbeGXHD3 (ORCPT + 99 others); Tue, 24 Jul 2018 03:03:29 -0400 Received: from mxhk.zte.com.cn ([63.217.80.70]:53880 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388161AbeGXHD3 (ORCPT ); Tue, 24 Jul 2018 03:03:29 -0400 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id D393C640F2208226E32E; Tue, 24 Jul 2018 13:58:39 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w6O5wXL7068236; Tue, 24 Jul 2018 13:58:33 +0800 (GMT-8) (envelope-from wang.yi59@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018072413583685-1465621 ; Tue, 24 Jul 2018 13:58:36 +0800 From: Yi Wang To: paul@paul-moore.com Cc: eparis@redhat.com, linux-audit@redhat.com, linux-kernel@vger.kernel.org, jiang.biao2@zte.com.cn, wang.yi59@zte.com.cn, zhong.weidong@zte.com.cn Subject: [PATCH] audit: fix potential null dereference 'context->module.name' Date: Tue, 24 Jul 2018 13:57:14 +0800 Message-Id: <1532411834-33775-1-git-send-email-wang.yi59@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-07-24 13:58:36, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-07-24 13:58:29, Serialize complete at 2018-07-24 13:58:29 X-MAIL: mse01.zte.com.cn w6O5wXL7068236 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variable 'context->module.name' may be null pointer when kmalloc return null, so it's better to check it before using to avoid null dereference. Signed-off-by: Yi Wang Reviewed-by: Jiang Biao --- kernel/auditsc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index e80459f..4830b83 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1272,8 +1272,12 @@ static void show_special(struct audit_context *context, int *call_panic) break; case AUDIT_KERN_MODULE: audit_log_format(ab, "name="); - audit_log_untrustedstring(ab, context->module.name); - kfree(context->module.name); + if (context->module.name) { + audit_log_untrustedstring(ab, context->module.name); + kfree(context->module.name); + } else + audit_log_format(ab, "(null)"); + break; } audit_log_end(ab); @@ -2409,7 +2413,8 @@ void __audit_log_kern_module(char *name) struct audit_context *context = current->audit_context; context->module.name = kmalloc(strlen(name) + 1, GFP_KERNEL); - strcpy(context->module.name, name); + if (context->module.name) + strcpy(context->module.name, name); context->type = AUDIT_KERN_MODULE; } -- 1.8.3.1