Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp940267ybt; Fri, 26 Jun 2020 15:43:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5wpOYk8fDSl6V9TnG7hq496dniXHfCzQaEKdXCtyc90Bw716WQu/sP0shNXFbynhAQBjP X-Received: by 2002:a17:906:5f98:: with SMTP id a24mr4374948eju.241.1593211387628; Fri, 26 Jun 2020 15:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593211387; cv=none; d=google.com; s=arc-20160816; b=xOViSbdrvmP5GJQgCga268pVGly3pmmJQKsibyYmBxLEOBnQRxXh7got4Q/EI5ZkBa 220M169pN3MY6Ru8ca47i82xMx6Vxp5cgBjC7p9ObmjYWmTtOc2AV1vRh9EgACeThQSD ngV8lxq47gn3hkg5bDG7WoxzFKssM/4Mvlqry10kVI8F1mcgx+zjTdcMR/xzELggKzlD cHtoDVKFNgcZsr6YAKA5LPt+AqY4rxpIyOJCCG1Q6YC8MfTQP3igkGTNqs3Oi79R2h9v mYRCdddzYLWG2K9U2zWEXQAPO70YMd8KpYAauPK68wx1o3P+//4Ya9n7b4I+Ux1ukREu 080Q== 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=NgaFLRWS7qo3ujL0AXOQBEum655blqojaYopmjuWreY=; b=i03efFPvZ4bfPhlRyJe6x/3AT1PDCbNFxNZ8czQls//Teh+nce+XlCYeaYyZ4vtLql kyRjDt86iBUTCT6uJCzhqFgKg3AIb5hCMkxWhX5GsYbIWD4gZgWA1JJOafWyUngY+XpK 0prtjOlmF9QodJxAeF0K6rOuIN7LhigFYchlG5odWk9Ybzq40AgTQ3RTazCnVn2S9RA7 jcyAQx6o6NHd0ZSj+zeW3rFZF9n3GcQ5+wnl9HVkFoRZ+tNNZyAlygbSsdxakmymk6/8 MCIUYHAd80wPPJnFgK/taGdMIUOOLHeFH8laH3jFAq41s7ZEpdanwFd+d8pApuh7sICb x96Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=TMlmjXk0; 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 sd17si3668591ejb.306.2020.06.26.15.42.44; Fri, 26 Jun 2020 15:43:07 -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=TMlmjXk0; 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 S1726563AbgFZWj4 (ORCPT + 99 others); Fri, 26 Jun 2020 18:39:56 -0400 Received: from linux.microsoft.com ([13.77.154.182]:37900 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726518AbgFZWjk (ORCPT ); Fri, 26 Jun 2020 18:39:40 -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 B322D20B4905; Fri, 26 Jun 2020 15:39:39 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B322D20B4905 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1593211180; bh=NgaFLRWS7qo3ujL0AXOQBEum655blqojaYopmjuWreY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TMlmjXk0FSfUS3DRx2rbvTApQ97nymuEYd2w1SK7TgThP+V41RqmU4Z20wPIc8pkr P/33ku1ExGN/cYx9Kc+qHlM4i5Z5o51b52HkECqtWNR1AL4dhZLJcAygDONh9dzScC RcmcidHdO+Wn0rMw2xLyQSp8mno3Zgb1qBauGVyk= 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 v2 07/11] ima: Shallow copy the args_p member of ima_rule_entry.lsm elements Date: Fri, 26 Jun 2020 17:38:56 -0500 Message-Id: <20200626223900.253615-8-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200626223900.253615-1-tyhicks@linux.microsoft.com> References: <20200626223900.253615-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 --- * 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 f9b1bdb897da..ef69c54266c6 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