From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jann Horn Subject: Re: [PATCH v2 3/3] initramfs: introduce do_readxattrs() Date: Fri, 10 May 2019 23:33:40 +0200 Message-ID: <20190510213340.GE253532@google.com> References: <20190509112420.15671-1-roberto.sassu@huawei.com> <20190509112420.15671-4-roberto.sassu@huawei.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mYLCrqAh6dGMRupORMTuLJWrL5feZF1QxoQSH4aJpzU=; b=SmumuDGrcJ5bVetydA2yfkeXDt1Z2G2LIlYxvLnjke6Wg5kUBXXcNJrpUGHKusgmwE kFJeBCfAGNRdUrFuqBTXEz4Ic5yc9HumCODEOzIUVLM4wpz1jB1Qwry3NgHtT0GfNvY8 hEELCbKgDlvLYvEnqJ7xfVDAacA4LStaGKQM3aCuez7I5adnI+YUK8qcHaLvi0kAdNJW xAt4ic4PdsVnHHeYJJNUakl4IqWCjXsE3Mq5+g8aGQvZztKIPnLVa76Yhq6+57WwkaHb r1ae7KbUmNyL0TkwxvZt46pVoXozcsc9QjHT1zGLG4Krw03zOYUplHe2CN0iYuT8y7N0 r1sQ== Content-Disposition: inline In-Reply-To: <20190509112420.15671-4-roberto.sassu@huawei.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Roberto Sassu Cc: viro@zeniv.linux.org.uk, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, initramfs@vger.kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, zohar@linux.vnet.ibm.com, silviu.vlasceanu@huawei.com, dmitry.kasatkin@huawei.com, takondra@cisco.com, kamensky@cisco.com, hpa@zytor.com, arnd@arndb.de, rob@landley.net, james.w.mcmechan@gmail.com On Thu, May 09, 2019 at 01:24:20PM +0200, Roberto Sassu wrote: > This patch adds support for an alternative method to add xattrs to files in > the rootfs filesystem. Instead of extracting them directly from the ram > disk image, they are extracted from a regular file called .xattr-list, that > can be added by any ram disk generator available today. [...] > +struct path_hdr { > + char p_size[10]; /* total size including p_size field */ > + char p_data[]; /* \0 */ > +}; > + > +static int __init do_readxattrs(void) > +{ > + struct path_hdr hdr; > + char str[sizeof(hdr.p_size) + 1]; > + unsigned long file_entry_size; > + size_t size, name_buf_size, total_size; > + struct kstat st; > + int ret, fd; > + > + ret = vfs_lstat(XATTR_LIST_FILENAME, &st); > + if (ret < 0) > + return ret; > + > + total_size = st.size; > + > + fd = ksys_open(XATTR_LIST_FILENAME, O_RDONLY, 0); > + if (fd < 0) > + return fd; > + > + while (total_size) { > + size = ksys_read(fd, (char *)&hdr, sizeof(hdr)); [...] > + ksys_close(fd); > + > + if (ret < 0) > + error("Unable to parse xattrs"); > + > + return ret; > +} Please use something like filp_open()+kernel_read()+fput() instead of ksys_open()+ksys_read()+ksys_close(). I understand that some of the init code needs to use the syscall wrappers because no equivalent VFS functions are available, but please use the VFS functions when that's easy to do.