Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1908673imm; Thu, 24 May 2018 02:44:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqlyTGNy7tYHmv3VodO6L9gRJRwjifdq6yM2/njlJ/iL+Zf726i6pL+Ie6wfdvA8JBaPvHU X-Received: by 2002:a63:7e1a:: with SMTP id z26-v6mr5279850pgc.339.1527155096619; Thu, 24 May 2018 02:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155096; cv=none; d=google.com; s=arc-20160816; b=ohrVbf9OKvRh9O9uKlPpYGjtjgQmOYH+V5ry4Pe41s1JZgAJOg40nPuyhPWh5QYAck WdKvBQ4xkbgu8ShjPY8G20znfM8qHWrGEAQi9p+D2i3KM2zEcqLr4kE0/jMtDwQylUVr QT9lkwEUWod12YHATJ6CUVZze7rTzENayrVfhgBXNF+4DpznpXddlj4Q/g1ZGK7cbGjk BPg1MGKCehG5LFtM5y0lQOcAi9VF9HKWpjq/su9iTQRBSUHaeyvJnQ3YdYYJyWr8/eqC ghqtDESQtOpKDSpkp1+AOwcZD1vgHo2lYcNSFq3ah82+d0S9/k+qIfQOChYV4bjeBbl6 aFHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=fw5LrBe8n02zidKL+z1IAEqdK2U2XdDeO03a2XOnDm4=; b=vzkSVRjw5o1gM4vKWFxvTTDqk5+9OAXroxHSg7IOqsn1og1abwPHIIIrHXCeNhh7Ql jDj7ph42j2IXZ+4UIsJiRjYTRL299gTsp1XPHPlsVFpbPai+DmXApCGE0X0E/TJlQ8j7 MjMazkeKXUgICC+9gkmbknne8QYw7eckIcWx2hrqpBy/rBLC/r6aYkA7RFdSlzKr3dCy 7TgHuJWKgjfIEJnDwsU1QkDp+vYp/DLSNmGNo1TtfJosHF/O2M/0V+a4FF4C2pni5aBc 18g1B0xJPg84ESwyXCDHsCMMyvqe8gTEvfEd2/JqgMFRvoyPEelR697HoYDQs6I2ZqI1 e44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wo80XnFt; 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 b26-v6si4285758pgf.324.2018.05.24.02.44.41; Thu, 24 May 2018 02:44:56 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Wo80XnFt; 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 S966498AbeEXJnb (ORCPT + 99 others); Thu, 24 May 2018 05:43:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:54878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966470AbeEXJn0 (ORCPT ); Thu, 24 May 2018 05:43:26 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 24558208B8; Thu, 24 May 2018 09:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155005; bh=WuURSlK1y9KQtq40OxoDNPmPWfoTVOwAejjLfjiy9/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wo80XnFt1uxaevGkECnt4wAVWhQSVbrQv+1qIVGQYZqY4XumwcZywBcL9BLgQhuIH QomldWcPWTqoO48/onkLEtJ+0q1cy8w565jwJUiJZx2R6hgXbjXe/l993/ISjkaR9T +hmbhQ8uxcvty6EClhUY5AIVdWdbyRyw8lIVBoLM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Guy Briggs , Paul Moore , Ben Hutchings Subject: [PATCH 4.4 21/92] audit: move calcs after alloc and check when logging set loginuid Date: Thu, 24 May 2018 11:37:58 +0200 Message-Id: <20180524093201.053650632@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Richard Guy Briggs commit 76a658c20efd541a62838d9ff68ce94170d7a549 upstream. Move the calculations of values after the allocation in case the allocation fails. This avoids wasting effort in the rare case that it fails, but more importantly saves us extra logic to release the tty ref. Signed-off-by: Richard Guy Briggs Signed-off-by: Paul Moore Cc: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- kernel/auditsc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1981,14 +1981,15 @@ static void audit_log_set_loginuid(kuid_ if (!audit_enabled) return; + ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN); + if (!ab) + return; + uid = from_kuid(&init_user_ns, task_uid(current)); oldloginuid = from_kuid(&init_user_ns, koldloginuid); loginuid = from_kuid(&init_user_ns, kloginuid), tty = audit_get_tty(current); - ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN); - if (!ab) - return; audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid); audit_log_task_context(ab); audit_log_format(ab, " old-auid=%u auid=%u tty=%s old-ses=%u ses=%u res=%d",