From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-f65.google.com ([209.85.161.65]:45515 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbeJBDJC (ORCPT ); Mon, 1 Oct 2018 23:09:02 -0400 Received: by mail-yw1-f65.google.com with SMTP id v198-v6so1224022ywg.12 for ; Mon, 01 Oct 2018 13:29:29 -0700 (PDT) Received: from mail-yw1-f42.google.com (mail-yw1-f42.google.com. [209.85.161.42]) by smtp.gmail.com with ESMTPSA id n186-v6sm18485815ywn.16.2018.10.01.13.29.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 13:29:27 -0700 (PDT) Received: by mail-yw1-f42.google.com with SMTP id m129-v6so6106339ywc.1 for ; Mon, 01 Oct 2018 13:29:26 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <44210861-2830-2321-911d-8783f5f0b172@schaufler-ca.com> References: <44210861-2830-2321-911d-8783f5f0b172@schaufler-ca.com> From: Kees Cook Date: Mon, 1 Oct 2018 13:29:25 -0700 Message-ID: Subject: Re: [PATCH v4 20/19] LSM: Correct file blob free empty blob check To: Casey Schaufler Cc: LSM , James Morris , SE Linux , LKLM , John Johansen , Tetsuo Handa , Paul Moore , Stephen Smalley , "linux-fsdevel@vger.kernel.org" , Alexey Dobriyan , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Salvatore Mesoraca Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed, Sep 26, 2018 at 2:57 PM, Casey Schaufler wrote: > Instead of checking if the kmem_cache for file blobs > has been initialized check if the blob is NULL. This > allows non-blob using modules to do other kinds of > clean up in the security_file_free hooks. > > Signed-off-by: Casey Schaufler Reviewed-by: Kees Cook This looks like it should get folded into "LSM: Infrastructure management of the file security". -Kees > --- > security/security.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/security/security.c b/security/security.c > index e7c8506041f1..76f7dc49b63c 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1202,14 +1202,13 @@ void security_file_free(struct file *file) > { > void *blob; > > - if (!lsm_file_cache) > - return; > - > call_void_hook(file_free_security, file); > > blob = file->f_security; > - file->f_security = NULL; > - kmem_cache_free(lsm_file_cache, blob); > + if (blob) { > + file->f_security = NULL; > + kmem_cache_free(lsm_file_cache, blob); > + } > } > > int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > -- > 2.17.1 > > -- Kees Cook Pixel Security