Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1775076imm; Fri, 7 Sep 2018 06:04:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYuYtOh7CZFaMBw29f5HcIRhlUNUtV5DA2yqbNIuD6WmnRJpnc62doIU4LVulXhHz6k7M3V X-Received: by 2002:a62:e511:: with SMTP id n17-v6mr8322944pff.210.1536325483037; Fri, 07 Sep 2018 06:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536325483; cv=none; d=google.com; s=arc-20160816; b=el0YS5/IJxwLkenPdwbUC/2okNe7LkjGvke47/ezerLFKjymu+ZX3oGp3J5dR9Km5K mvuqbXHjihB3Pqh3c/yI8PeXwp2ftgDF5EyaDNVtWFeiQ2YkEGvrR8Fz4NEpmq1g1vlS Ed96FOBjClxbEsycZEhBaCIczyfgGhcoKEF3QL+EKVouOSmUTfrhmfadKv+cJqJUSA+X r4EBJls/GTReMssVuZqhvaqh98D7UFdRrShc7Bb+ollSa3bexI3/au1saTkbo4WtR5W5 W+NwFd/MFsUU+tZS2JhAhBZTDvnyfPIqUju/r3jmfiwn5/aw5lJgwEFrYflhrWmou7VL /N7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=nz0xVx7RgFfCZFIqKk/revBjSD24ymWLUqWZqPA+6W0=; b=MEelHNJPIhY0mVfJnZ2eDxMEjVMYQz3htF4EPuh9mk+FEXXJ9AN9vdFPAcSv6pZots 1Vlng30JWqIz1ZzSeXkI4qRbgbcEd/6mm9p0OEarNYpxBylmncJ68aV1Ko2ioYmYl478 TSixpUjPh43qi6hV/mma6FWjKc2KF3bOnfXXrOHrrmKUElqG3W79eJER29Pg1csU+kkp rU3WR3xtKY+gJdogsYO91gxs/6uj8xc7fs8WL/ruZtRhYXfAFMQ8MH1hep7fEBXrIv+u 8krbb6ticQ30jFWgFsCDTX87KjTFJ622XsMGx8/5XLXHUEmTQM1WpWbqEeEfoISG8r+w lYpQ== 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 h14-v6si8445825pgg.540.2018.09.07.06.04.27; Fri, 07 Sep 2018 06:04:43 -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 S1729464AbeIGRT5 (ORCPT + 99 others); Fri, 7 Sep 2018 13:19:57 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:34483 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729453AbeIGRT4 (ORCPT ); Fri, 7 Sep 2018 13:19:56 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fyG27-0007c1-Q5; Fri, 07 Sep 2018 14:38:43 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fyG26-00062O-HX; Fri, 07 Sep 2018 14:38:42 +0200 From: Sascha Hauer To: linux-mtd@lists.infradead.org Cc: David Gstir , Richard Weinberger , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Sascha Hauer Subject: [PATCH 16/25] ubifs: Add auth nodes to garbage collector journal head Date: Fri, 7 Sep 2018 14:36:37 +0200 Message-Id: <20180907123646.12688-17-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907123646.12688-1-s.hauer@pengutronix.de> References: <20180907123646.12688-1-s.hauer@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To be able to authenticate the garbage collector journal head add authentication nodes to the buds the garbage collector creates. Signed-off-by: Sascha Hauer --- fs/ubifs/gc.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index 399d764f83cb..bf75fdc76fc3 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c @@ -365,12 +365,13 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) /* Write nodes to their new location. Use the first-fit strategy */ while (1) { - int avail; + int avail, moved = 0; struct ubifs_scan_node *snod, *tmp; /* Move data nodes */ list_for_each_entry_safe(snod, tmp, &sleb->nodes, list) { - avail = c->leb_size - wbuf->offs - wbuf->used; + avail = c->leb_size - wbuf->offs - wbuf->used - + ubifs_auth_node_sz(c); if (snod->len > avail) /* * Do not skip data nodes in order to optimize @@ -378,14 +379,21 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) */ break; + err = ubifs_shash_update(c, c->jheads[GCHD].log_hash, + snod->node, snod->len); + if (err) + goto out; + err = move_node(c, sleb, snod, wbuf); if (err) goto out; + moved = 1; } /* Move non-data nodes */ list_for_each_entry_safe(snod, tmp, &nondata, list) { - avail = c->leb_size - wbuf->offs - wbuf->used; + avail = c->leb_size - wbuf->offs - wbuf->used - + ubifs_auth_node_sz(c); if (avail < min) break; @@ -403,9 +411,41 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) continue; } + err = ubifs_shash_update(c, c->jheads[GCHD].log_hash, + snod->node, snod->len); + if (err) + goto out; + err = move_node(c, sleb, snod, wbuf); if (err) goto out; + moved = 1; + } + + if (ubifs_authenticated(c) && moved) { + struct ubifs_auth_node *auth; + + auth = kmalloc(ubifs_auth_node_sz(c), GFP_NOFS); + if (!auth) { + err = -ENOMEM; + goto out; + } + + err = ubifs_prepare_auth_node(c, auth, + c->jheads[GCHD].log_hash); + if (err) { + kfree(auth); + goto out; + } + + err = ubifs_wbuf_write_nolock(wbuf, auth, + ubifs_auth_node_sz(c)); + if (err) { + kfree(auth); + goto out; + } + + ubifs_add_dirt(c, wbuf->lnum, ubifs_auth_node_sz(c)); } if (list_empty(&sleb->nodes) && list_empty(&nondata)) -- 2.18.0