From patchwork Mon May 13 12:53:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Karhunen X-Patchwork-Id: 10940863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A00261390 for ; Mon, 13 May 2019 12:54:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9436527F60 for ; Mon, 13 May 2019 12:54:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8891A27F82; Mon, 13 May 2019 12:54:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F44627853 for ; Mon, 13 May 2019 12:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730040AbfEMMyi (ORCPT ); Mon, 13 May 2019 08:54:38 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42426 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730034AbfEMMyi (ORCPT ); Mon, 13 May 2019 08:54:38 -0400 Received: by mail-lf1-f68.google.com with SMTP id w23so8956919lfc.9; Mon, 13 May 2019 05:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YDGj9rVkvE8XZld5lFXG+QIkeDeoJDurNDlY5dYrCpo=; b=XE04hlQkBchBUXgcGRWR4Jw6UPX9mcLpmQGKBKbZg8hioEveJttbj6pIDs5U43zi4f MnIG+a1pWRqCQHD93XoA0aXixI/0+g3ExLqNQt9orbk/pnyLnn9IDmsT1FdrNDVVtjm4 3BSc0ouTluJwoihs10/h4PC5oWS7LcPsnazpgs6T16A4keFqk5ciw0P7AhYQUcMjmxIA fubKyAkGp2w54elwmf/8HYycLlWIe5vichCHGDLgYe3x39fIhfIcDFhyxXcnnY9Vhs87 tLcXmARbjkdvyPmML3lJp54lZkQvdMLhapTpOXuzPoRNLOqF/Mf/12/BCqgUd+Sp9urF 135g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YDGj9rVkvE8XZld5lFXG+QIkeDeoJDurNDlY5dYrCpo=; b=ZHL7O30hNhUFz73OmANpoFoqdicotyil4qHYzQbPrO/cKe1nrYrIGRUouyc4aW3U/o 9pbUkvTCSFAQa4+DRFr3Iq7TG9R7ciMB1jN5j7tT5iUgksDZ7kfraq4FlfuIYO6Wu1ln 6ISqhY8tZ5oZAoLd0NKFwPFIfC10MHqg2NN2TwukUzBTqEQ0gkC4Y4xUzDKImfAbPB4f OoUh3DY0NaYCicgzexkbpFjoBqRIUnsvGzLkpJSvyT5RuXdZFCfrdNfPNSMWjctPktYo 149V+ZpuHIjpYwL7gskQkEJwO/bZ/5iYcet3H/KcTTkYtARt2YyxuoYIhj+8sce28bHK FSMg== X-Gm-Message-State: APjAAAVPhlLjUs0UvUwMOHk9vGnQQD77A7hgcUQrtDKiZdnFgCGhZCr2 6/NjbCHLbHv9+KAX2nMS9z+QPB7Z1r8= X-Google-Smtp-Source: APXvYqzDO3AdUUpn1HJ9XHgficGSyDLCnABfId/VCfp8rMP+P4CjdKQj8qmGU1J0hA6BzHMdvS3Q8Q== X-Received: by 2002:ac2:528f:: with SMTP id q15mr12733938lfm.37.1557752075897; Mon, 13 May 2019 05:54:35 -0700 (PDT) Received: from localhost.localdomain (mobile-user-2e84ba-11.dhcp.inet.fi. [46.132.186.11]) by smtp.gmail.com with ESMTPSA id t22sm3202924lje.58.2019.05.13.05.54.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 05:54:35 -0700 (PDT) From: Janne Karhunen To: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, zohar@linux.ibm.com Cc: Janne Karhunen , Konsta Karsisto Subject: [PATCH 3/5] integrity: update the file measurement on write Date: Mon, 13 May 2019 15:53:52 +0300 Message-Id: <20190513125354.23126-4-janne.karhunen@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513125354.23126-1-janne.karhunen@gmail.com> References: <20190513125354.23126-1-janne.karhunen@gmail.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When a file is being written, mark the file for IMA for delayed re-measurement. Depends on commit c8213962517e ("integrity: keep the integrity state of open files up to date")' Signed-off-by: Janne Karhunen Signed-off-by: Konsta Karsisto --- fs/read_write.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 177ccc3d405a..bfe10d6dc135 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "internal.h" #include @@ -481,12 +482,18 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t static ssize_t __vfs_write(struct file *file, const char __user *p, size_t count, loff_t *pos) { + ssize_t sz; + if (file->f_op->write) - return file->f_op->write(file, p, count, pos); + sz = file->f_op->write(file, p, count, pos); else if (file->f_op->write_iter) - return new_sync_write(file, p, count, pos); + sz = new_sync_write(file, p, count, pos); else return -EINVAL; + + if (sz >= 1) + ima_delayed_update(file); + return sz; } ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)