Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1154264ybt; Wed, 8 Jul 2020 23:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws2fQ/fYeJ2JwaBpbR5OIGkifQ7ANjwSNVyKDDICEemysHtJVX4W6Sxn+oef8fbCizod/c X-Received: by 2002:a17:906:a449:: with SMTP id cb9mr35006804ejb.115.1594275735187; Wed, 08 Jul 2020 23:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594275735; cv=none; d=google.com; s=arc-20160816; b=ubcwcCNFttLcpmhqfF3LKjoDto7UTUSSSx+wL13vq6ERU8nISbudzTr0Gd8TN/bu66 +BStNnrDZVirF1TTRUAFaQqs0jf0xYWTWMHSaFMdpdB69J8Bqgsj/vBVgIsYbLAaNcJ6 /LWPdcfSzQVlaqNua+WdpsToShH2aYWPQT/0EgX5j5tppXGJiMwq+Gc+S3Q3HECwxdHh f4bElT/o6apTlYxPBuh3dyB4K7QSpwNkqJlpF25KWNEJHpfzSGC/tlB5UbC/RvuNqj9Z 461lWblanClkga1yuev0D0+PO3SUy/yF1akT7uZP1xZMcf/RT18CExUra1dvvgFVkQke dSVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=kdGo+g0Ug/+ndalVCdzuX/XIssnW7sZa5n/LdXUX1OM=; b=COo4QZzCZWh6W3CRZy1cvSc9/xZg7lZsdwN2yfnAlpWoafhdsPeBP7mxvEwY/XH4sd bQDo/2b2NqbXe4KJqvpEJSqo4U+Ai5RVBAe0G1fPPhm7gpazjIvszzSJtMSFjYSlikJe FMXwm7E8lm6LfdZdFKf+0JY5NYDl8fdrG1HaHyK5uKZjLAcK5aW7jrLfm6ajXMLNt5JF 6YG6czknbNplGsg/fzqeJXwKvURDUkAvXEuqir+HKSlJI3d6RY6unxX+4BvWlSTTsZRB ItDb3z1b5WyVnwjglQK8s4iOcDN6BhMWdrOl0LOGYvOU0gfMYX7Tcw1zvJ8AbMWwBO3W C9IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g7f7y5H5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s27si1251005edw.322.2020.07.08.23.21.51; Wed, 08 Jul 2020 23:22:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g7f7y5H5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726778AbgGIGUg (ORCPT + 99 others); Thu, 9 Jul 2020 02:20:36 -0400 Received: from linux.microsoft.com ([13.77.154.182]:38096 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726581AbgGIGUM (ORCPT ); Thu, 9 Jul 2020 02:20:12 -0400 Received: from sequoia.work.tihix.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id ED52220B4909; Wed, 8 Jul 2020 23:20:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ED52220B4909 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1594275611; bh=kdGo+g0Ug/+ndalVCdzuX/XIssnW7sZa5n/LdXUX1OM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7f7y5H5XpYSW/JqRJeaI3n/zw1XVmSYLKBZA3ZBwjh3RAvvCTvC6hDloRL5oNLGT 1ZTeusQjwRyMyX8hLF/RbnyRh9kx0ArCJoWQVWs8CB3V3xt6qevpWkxEMjlG2rTIiD MerMF1DJfyii9F7c6vAGHXSWuZtO3sf2EjsznJx8= From: Tyler Hicks To: Mimi Zohar , Dmitry Kasatkin Cc: James Morris , "Serge E . Hallyn" , Lakshmi Ramasubramanian , Prakhar Srivastava , linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v3 08/12] ima: Shallow copy the args_p member of ima_rule_entry.lsm elements Date: Thu, 9 Jul 2020 01:19:07 -0500 Message-Id: <20200709061911.954326-9-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200709061911.954326-1-tyhicks@linux.microsoft.com> References: <20200709061911.954326-1-tyhicks@linux.microsoft.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 The args_p member is a simple string that is allocated by ima_rule_init(). Shallow copy it like other non-LSM references in ima_rule_entry structs. There are no longer any necessary error path cleanups to do in ima_lsm_copy_rule(). Signed-off-by: Tyler Hicks --- * v3 - No change * v2 - Adjusted context to account for ima_lsm_copy_rule() directly calling ima_lsm_free_rule() and the lack of explicit reference ownership transfers - Added comment to ima_lsm_copy_rule() to document the args_p reference ownership transfer security/integrity/ima/ima_policy.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 9842e2e0bc6d..b02e1ffd10c9 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -300,10 +300,13 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry) continue; nentry->lsm[i].type = entry->lsm[i].type; - nentry->lsm[i].args_p = kstrdup(entry->lsm[i].args_p, - GFP_KERNEL); - if (!nentry->lsm[i].args_p) - goto out_err; + nentry->lsm[i].args_p = entry->lsm[i].args_p; + /* + * Remove the reference from entry so that the associated + * memory will not be freed during a later call to + * ima_lsm_free_rule(entry). + */ + entry->lsm[i].args_p = NULL; security_filter_rule_init(nentry->lsm[i].type, Audit_equal, @@ -314,11 +317,6 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry) (char *)entry->lsm[i].args_p); } return nentry; - -out_err: - ima_lsm_free_rule(nentry); - kfree(nentry); - return NULL; } static int ima_lsm_update_rule(struct ima_rule_entry *entry) -- 2.25.1