Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1043635ybi; Wed, 19 Jun 2019 12:23:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfJE/gBS55OHuDfGaEaEtx45FFpfcKZGUPdJ+zqHHl15ANJ4ivLeeBjMkZuSYIbZbAb38z X-Received: by 2002:a63:8d4c:: with SMTP id z73mr3428469pgd.95.1560972207496; Wed, 19 Jun 2019 12:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560972207; cv=none; d=google.com; s=arc-20160816; b=R9e1u3WnJ1r7tuXdC3ZrhnMLVIWxGkMy+R5i5yhaXbe1oGIT3AumFilaXm2Q6fsD2g 8CKdusj712XbclDBIwimbqRZvVI756ycAYleaeKsVcg6/xHC7hn9mEra51L2EGpCxual aNV564zmk4/dbd4lCmYNOKgo7Db8LSKalU/Y5H4xaMfqjEoxULOxWGFmKlW5SFoba88W eVmHLJxwYs78WV0B0TW9kbZHAOB22ybFmXh6I2MqsfD7VhDl+p7j8loYdaLrvdGoE7sL aik23VMxUjH3yxE26EKkS5yblEf8oVxncVRSbLwGZxYVrc9MJa/96creAigMYVM1/rWD XRNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject; bh=6LbO1Q8GyDda3xj1+ImeoF/+QKsnbLqCxiRS2v2VXkA=; b=ciX8yd+ZWiNpF6fJMFT/fwbVUIGkIcT4ZeIeE9gba0lOz4g17wAWm3Gu3M9HSkAxbv RFNb+HoabglnaUTHWbNZefUpGrJlHgu8dCURIwu3LALP2y00W6e9d6p5mKvAzt9aJSr7 LDm93VElhFdL6ky3NyoH7QTzrzwWaDk1ZbDZj65+6wUmDeP/QQGTfsf6mNkChP7W4WNc maR3pPkrUnWNRaOPv4Js6YD17qb0uGRO7cnuBrYRTXS9qbTMueDH1Iu1Hmso6Ke05SsP g9bxA9TJPu54GZekH28rSEp1/mSs8s0W812Fqw0FW5B9OHQunekmXBOVW3P/fqp5CBNv R9Zw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z17si3644074pgv.485.2019.06.19.12.23.12; Wed, 19 Jun 2019 12:23:27 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730165AbfFSTVt (ORCPT + 99 others); Wed, 19 Jun 2019 15:21:49 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:20752 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729659AbfFSTVs (ORCPT ); Wed, 19 Jun 2019 15:21:48 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5JJH5MO129644 for ; Wed, 19 Jun 2019 15:21:47 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2t7tqhs6fm-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Jun 2019 15:21:47 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Jun 2019 20:21:45 +0100 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 19 Jun 2019 20:21:42 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5JJLXqn35324182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jun 2019 19:21:33 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C01342056; Wed, 19 Jun 2019 19:21:41 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B271142042; Wed, 19 Jun 2019 19:21:40 +0000 (GMT) Received: from dhcp-9-31-103-88.watson.ibm.com (unknown [9.31.103.88]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 Jun 2019 19:21:40 +0000 (GMT) Subject: Re: [PATCH 1/3] IMA:Define a new hook to measure the kexec boot command line arguments From: Mimi Zohar To: Prakhar Srivastava , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: roberto.sassu@huawei.com Date: Wed, 19 Jun 2019 15:21:40 -0400 In-Reply-To: <20190617183507.14160-2-prsriva02@gmail.com> References: <20190617183507.14160-1-prsriva02@gmail.com> <20190617183507.14160-2-prsriva02@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19061919-0012-0000-0000-0000032AA63D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19061919-0013-0000-0000-00002163C8AE Message-Id: <1560972100.3975.72.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-19_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=11 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190158 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-06-17 at 11:35 -0700, Prakhar Srivastava wrote: > Currently during soft reboot(kexec_file_load) boot command line > arguments are not measured. Define hooks needed to measure kexec > command line arguments during soft reboot(kexec_file_load). > > - A new ima hook ima_kexec_cmdline is defined to be called by the > kexec code. > - A new function process_buffer_measurement is defined to measure > the buffer hash into the IMA measurement list. > - A new func policy KEXEC_CMDLINE is defined to control the > measurement.[Suggested by Mimi] > > Signed-off-by: Prakhar Srivastava With minor changes below,       Reviewed-by: Mimi Zohar > --- > diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c > index af341a80118f..1e233417a7af 100644 > --- a/security/integrity/ima/ima_main.c > +++ b/security/integrity/ima/ima_main.c > @@ -605,6 +605,80 @@ int ima_load_data(enum kernel_load_data_id id) > return 0; > } > > +/* > + * process_buffer_measurement - Measure the buffer to ima log. > + * @buf: pointer to the buffer that needs to be added to the log. > + * @size: size of buffer(in bytes). > + * @eventname: event name to be used for the buffer entry. > + * @cred: a pointer to a credentials structure for user validation. > + * @secid: the secid of the task to be validated. > + * > + * Based on policy, the buffer is measured into the ima log. > + */ > +static void process_buffer_measurement(const void *buf, int size, > + const char *eventname, > + const struct cred *cred, u32 secid) > +{ > + int ret = 0; > + struct ima_template_entry *entry = NULL; > + struct integrity_iint_cache iint = {}; > + struct ima_event_data event_data = {.iint = &iint }; > + struct ima_template_desc *template_desc = NULL; > + struct { > + struct ima_digest_data hdr; > + char digest[IMA_MAX_DIGEST_SIZE]; > + } hash = {}; > + int violation = 0; > + int pcr = CONFIG_IMA_MEASURE_PCR_IDX; > + int action = 0; > + > + action = ima_get_action(NULL, cred, secid, 0, KEXEC_CMDLINE, &pcr, > + &template_desc); > + if (!(action & IMA_MEASURE)) > + goto out; "out:" is a simple return, no freeing memory.  Just return here. > + > + event_data.filename = eventname; No need to initialize even_data.filename, here initialize it when it is defined. > + > + iint.ima_hash = &hash.hdr; > + iint.ima_hash->algo = ima_hash_algo; > + iint.ima_hash->length = hash_digest_size[ima_hash_algo]; > + > + ret = ima_calc_buffer_hash(buf, size, iint.ima_hash); > + if (ret < 0) > + goto out; > + > + ret = ima_alloc_init_template(&event_data, &entry, template_desc); > + if (ret < 0) > + goto out; > + > + if (action & IMA_MEASURE) Why is this test needed again? Mimi > + ret = ima_store_template(entry, violation, NULL, buf, pcr); > + > + if (ret < 0) > + ima_free_template_entry(entry); > + > +out: > + return; > +} > + > +/** > + * ima_kexec_cmdline - measure kexec cmdline boot args > + * @buf: pointer to buffer > + * @size: size of buffer > + * > + * Buffers can only be measured, not appraised. > + */ > +void ima_kexec_cmdline(const void *buf, int size) > +{ > + u32 secid; > + > + if (buf && size != 0) { > + security_task_getsecid(current, &secid); > + process_buffer_measurement(buf, size, "kexec-cmdline", > + current_cred(), secid); > + } > +} > + > static int __init init_ima(void) > { > int error; >