Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2591538yba; Fri, 10 May 2019 14:36:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJQjCyPi+a5d5xMzMgYiEzCTzQKN3j6L9wxQbEYqaWUB4+XBzhfhXuIf8Sv/c9f5diSkNH X-Received: by 2002:a62:4558:: with SMTP id s85mr17706683pfa.171.1557524178904; Fri, 10 May 2019 14:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557524178; cv=none; d=google.com; s=arc-20160816; b=rq6q0XSVmc0YOsEZpfK3RoRCziTiCKcITUJp7qtLdHERuUZ0lutuuNggt204NEbRfs QuQCAzBfls3wNDwGzYHzj1QDwYwZ1gc2Ww4ZbL90C6d0wEinSyaZTvC9UeuGvW96OXTb WBOoDUtWQQz6l7N/4fjCKu74B76VFjn1WLuXXGEYrUnpEBwEgoeSCZxW6gLBum+9Wsqd JYJC52Ib2UFgiDR9RKxPu5U+MBlEIhO7xONlv39wKIqUHUjb1wZIXYUNGLjftKx2XwFN j49zJaniQo6Ayb/BDPerHP+QnbPaVISoijHK6DnfeTtiEPd3vRXh4GbGp2xZknlD2WxM S4UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mYLCrqAh6dGMRupORMTuLJWrL5feZF1QxoQSH4aJpzU=; b=SsM42wiLl3YTsnv95FTwigFAVTHSh95cN1YAAMzINDJYQUyASALhJ4LHgwWJnGrLzJ OdYaMKZAu1fJUCyCS7DfCMAUJjh0N9ra5Pr7xYiEI9X2/18QcTCTzg+xHDpFrB4FWFX0 CWrJG91MFUX40mr+GOMS/O85VzNUCUMqyZSRNXEt3I5nawTfFX12KoDDFSx4ohoZL7sB CvB0BwjafJUCEVgvdqVtAejCJxjaM+7UulBfSV0fxipH5GBRXipxYaazWVTctpjoTpQ+ bK6A88cciYvpd49BnHokcUJGbm4TJbzaqiEvEBqD0Y2q4rWkD5R094LZa15nJ9W5j13p TR4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SmumuDGr; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m72si7575774pfi.96.2019.05.10.14.36.02; Fri, 10 May 2019 14:36:18 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=SmumuDGr; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728248AbfEJVdt (ORCPT + 99 others); Fri, 10 May 2019 17:33:49 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:35636 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728231AbfEJVdt (ORCPT ); Fri, 10 May 2019 17:33:49 -0400 Received: by mail-ed1-f65.google.com with SMTP id p26so6978478edr.2 for ; Fri, 10 May 2019 14:33:48 -0700 (PDT) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mYLCrqAh6dGMRupORMTuLJWrL5feZF1QxoQSH4aJpzU=; b=tX6b6O/UtIPnfENmlZkI/oZpQcSqCnwwvhofKsUr7X43l4+LC51oAKbEaQjDtldnAY EswvsDhdg4uWwpRdCYB1iLGguQlY2nEx0/cwZSvNDeJGvqShvwNQsf7kabkNOstRuHRN BQDxJi81504yj2lF90F4/NY6i4lEKoTcbHz+Of4vbnOLAAz4Oo8c00mP+yfDTYqnVKaY zQVlJLnQgcT5NytptKJbrlAPNhXRagvjcTnn5H9WmA+lXSbh5RcfcYlpt+Uquxr37Mfk bN99YNFNPXLqn+zLytsG8s5Zx6v5hrdHlNfHe8nBOyKdZzrSloxtYMcRUjZw0U4Dwr9x 6KUA== X-Gm-Message-State: APjAAAW6VgOZqhFlWisYDGXGs/OeWBb5NwNftBxwh3T3Ft3aKmrpH/2z AEPYUM6A91Xnfjj9oWSSXrY4Jg== X-Received: by 2002:a50:a495:: with SMTP id w21mr13800142edb.78.1557524027343; Fri, 10 May 2019 14:33:47 -0700 (PDT) Received: from google.com ([2a00:79e0:1b:201:ee0a:cce3:df40:3ac5]) by smtp.gmail.com with ESMTPSA id 65sm1685486edm.60.2019.05.10.14.33.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 10 May 2019 14:33:46 -0700 (PDT) Date: Fri, 10 May 2019 23:33:40 +0200 From: Jann Horn 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 Subject: Re: [PATCH v2 3/3] initramfs: introduce do_readxattrs() 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190509112420.15671-4-roberto.sassu@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.