Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5305026yba; Mon, 13 May 2019 08:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpzRjXBvSqhBRRaGE6ZGGnP3Kf7c7PXT1j3ETFTIZe/PY/xOO2AJYLorqNqqTqnODxEmMQ X-Received: by 2002:a63:4346:: with SMTP id q67mr31891188pga.241.1557761996770; Mon, 13 May 2019 08:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557761996; cv=none; d=google.com; s=arc-20160816; b=MaBkHwIFbFEYcoaxeT3IUWrX1suAzvvWY/qiJPZoetYQd9oohXjpAJBbodsSneDksp 3x260AoVhhFEYxGjD6ydP997FxQH7xRH79/lDLh7LlI9TGkK96rqogyTcg6rT0OlBRdy pdIh8uPibwDm1YmLUyPhSMetncusZ26nhFHwqBfPadQdWfCzpq07feEf2I6eRFhXgLNe dby1Fc7+Q+2XwaiNj4lO55PdGIQj6+ihMYE/7iuFfmA6HRNX6JdpzxlngWaqzyBdG27B IRVKkz0JooSoCf+xoa229VM5RakJfREZkC4HlqR57vcfZRJLtN1YryFJPOUm+pDTi0I5 jdDA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=TAT0kFdEoFp8hwWqnD7QglJbxFdshQXf78XKLNaQN5c=; b=mjpvBIJYEHUED8Pp4/QocHhuU2RPr5UX+n3Snon5j/wey2QM30b890BPFgZ5CXpfjH ogNEvbvuBAtQH3D+bYYyRVJBB4Rp9jbyhzowFCUsLavESrggjJYKXXhr5eiKewEE/BgG MboRumPz+zwWP2OTTrRSO9e3eDlhNJ++wxZ8p3Exf647UdC8YgXEnPWhWHjdzwxhWcYU iT7Cc4kzwv15tUf5YM2SkAP4G6tce4OARKktbN8cBpFrfhabhFReTLeJLnlRXn7ILOha d/+YzAEJQlvTccnzj5Or1kHdEjXFtJ7WvC0fP1W0OL6undM6QBTk3GO3lPxDtnlgJxpY UPlQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i22si13650499pfj.21.2019.05.13.08.39.40; Mon, 13 May 2019 08:39:56 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729755AbfEMNDq (ORCPT + 99 others); Mon, 13 May 2019 09:03:46 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:32935 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728743AbfEMNDq (ORCPT ); Mon, 13 May 2019 09:03:46 -0400 Received: from LHREML713-CAH.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 134B4B112C6D8409069F; Mon, 13 May 2019 14:03:44 +0100 (IST) Received: from [10.220.96.108] (10.220.96.108) by smtpsuk.huawei.com (10.201.108.36) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 13 May 2019 14:03:33 +0100 Subject: Re: [PATCH v2 3/3] initramfs: introduce do_readxattrs() To: Jann Horn CC: , , , , , , , , , , , , , , , References: <20190509112420.15671-1-roberto.sassu@huawei.com> <20190509112420.15671-4-roberto.sassu@huawei.com> <20190510213340.GE253532@google.com> From: Roberto Sassu Message-ID: Date: Mon, 13 May 2019 15:03:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20190510213340.GE253532@google.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.220.96.108] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/10/2019 11:33 PM, Jann Horn wrote: > 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. Ok. Thanks for the suggestion. Roberto -- HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063 Managing Director: Bo PENG, Jian LI, Yanli SHI