From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DF9D29DB8F for ; Wed, 18 Feb 2026 13:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.221.42 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771420723; cv=pass; b=LLw8FvwhYZCk42NQzsa/iibVuNIZrIujs2LomhfqSnWhzh+bD6+IgljYQP9nGXLE64L9DNLbvHWqTp0K0iV/qFkeUjw6DLZD2MJ6Hv2Gz1zn1w/ru5L0TwC2Guu9HtvM20/xnV+GnWaSXRdxaZpn5EVc3Ps870iL7QJs735+xeE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771420723; c=relaxed/simple; bh=sLMGR09zI4y3gpjzSi6grOOg7wQjmI4f5Efbabe2ap4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=L5mlIN5Myu3tfau9vi3ppQfDYpZYx/dC6bgdTW9CSLuvZgavoklFwTs9ELYvu3c/A+csgvC/PNpAWUW5hWp+J2P72+VGSk4k1xCLYz3NZ98k+toMNETin5bQU6Dge3U/MuF9SmQ68NSl+sg4ZLLj9JdgpVOBzHUsVL6thwwUNtc= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Onq8ALfd; arc=pass smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Onq8ALfd" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-4327790c4e9so3936004f8f.2 for ; Wed, 18 Feb 2026 05:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771420719; cv=none; d=google.com; s=arc-20240605; b=P0Xab5AXMJ+wc6z6XiLwF2a5xkp6qCBwCLuixIN/l7lYZKBn1DCnpWTucYVlPxOG0b iW/awt89j+C9KCK5pVPzn4rKhrhYpogQ4JxWYBwW9f/FOVBsW25LTtY7k5/NMaX5t8QN 2dEAk/Y6DOithDToE80YQuhEvge/ZXG/TDv8dD2xWY7vxdevIalRrzMZuHTYY/TYn88G /wvFpkYLuuK0TRM8f3l/yCErO//aEwEXUkctPlpbascOss3VBHEgberOpnMBW22eRlHx ItC8OeWZyHyExVHMITKPxiuAGJLGhtM0fXyoudsFw1TNNeL9Gbvp92Xbd1EPhfuIoXf0 sR1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=RHxjjrT8dDKAZN0w50HLXW8C36xUtCBdYdPVz0Pgsc8=; fh=wqxtpQ1saDubzj7AtOBCQ62q0X6J2KndUEDsoBqpXYA=; b=ejJTmv4ohTnjhwQr58DJPZvy7jfKJ//Gk8vM9SundMFj39Bm4TTw617upvnMc4C3XA G3y9QykXyIP6gxWkCUYQRc6+Yn5hCPlTAqzy0VUJpA5SKt14Je0My2ErrRQchCB7v+ky DYhaxVvwG34YFM21R70kGknBPcQCjjO4oORndzHQxrGShfcf7vodFVXj1I+wloS5jUK9 9iT9na06rfCidyVuVSm3F8JgIhB5n8+OsY6sEde5WFb9lZ27B4nICYmflFl6wEm2nbDF qhklZWwulWHMpWL7v73x/I//xarchhkbz7yL7mqDjf0cvOSrQxDKHl7lsXnwj3crmyUL exIw==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1771420719; x=1772025519; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RHxjjrT8dDKAZN0w50HLXW8C36xUtCBdYdPVz0Pgsc8=; b=Onq8ALfdPQu6Dgw3a15nKbA09J6rzOwkPAfTk8y9o9yjRD3hqfqxCygRhg/J1sLKfM Zda5bkTSUgAHkYZ2+B2mAFmjB6ppVM8wLv27EGpnDQwFb+GlpW6Uyte60rYXZ/8e0ln2 EuVFhhGluTzk3tW/Fdrs2OW/oWgIN1edYnlXhbo7Uc3Q4n0yo/YISsXUI/5xk6YcwfeD SU5IVMR1MzlTKb2N/eeJyfLmw6Kdf79yYFdTbCz1tAEq+u/4S+SBqsdpH833JE1w5Quh 4PWRWOUoT773pY2oqnObD4ayXyAnXLMsF8T4bkTlnQnul9dCmLQgJ4Oi+qw83KsFdXXR t0ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771420719; x=1772025519; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RHxjjrT8dDKAZN0w50HLXW8C36xUtCBdYdPVz0Pgsc8=; b=wGLxYNqngxpaPpqvvIAFcqfO4SkShUx9MWkAuQGgeVplgbO693bS+TrZOOR0jGJPbJ c1QusivapRPyQX5OAT3Bc0DpCV9V17ezU/i7hbWahdA9BctHZrdQbMKXKlU0bEV7sAZB nlOCHoe3ogvn4j0vcrhBezQTkdtxm9Yw8Qz9d2A2pSWdPQ5qEW07TBPPBjqDJu6I9EBt crrShLRZmDh1mgPofoQ4HWdo4tgCumskL41VUnQns22D63QIuVit8/FAzo5n9uCN51hQ VNVI6/9hV951TRTa9iXcb7IZ5URuutrwnJvXdlrjtzdEb7MlrIqa4pfi39QOAZu5G4Ln iBdA== X-Forwarded-Encrypted: i=1; AJvYcCVh5igfJ/o9q0BrFgWDnKmXRwngXzpxQoYC2CyA2mS0MDeszfHB/qrQTJ6JgWv/UV6NzAAM/IlZBcAIy5s=@vger.kernel.org X-Gm-Message-State: AOJu0YzWLsYHFCZ0DdVAXq/5nnOp2nrOP8GD5R6HWTf2v/UCsU6+eUKt MMLVw2tY34XEMrFNeB0fOT7rtOefqhYAccehNd3m5N1ZVUUoMhI2/PeA01dOYAgHxaXW548ZUvM 1uFvUFpOx9gdvF4OrK2/PSmSentf8Lg/WzS4CdKqnsA== X-Gm-Gg: AZuq6aIhJHAN5Nw2zuQ7q/Bu0KhV6UGr5pPazMT71nKmQyH7F6aBPA0L0NobkDQNpxQ N6yiTpH3RVSDoDBHc7y1lddxeY8ItHm6fuXyVF27HiGmKLdL+5p+TZY7QFAag2CtuYiZ857P3BB votrGUmEAbkO4ccjZHcap2MqDx+Mc+4oS7/6LMXMP+j817ksvtMWoP041xgN8Nj95t/L6Ii3mHh kz6UiGGnZooqP5/xBqY5isnhjgdxs1kp8kc+lM48y0hsMwjgdYcsGZz0ptgktzhXp18+YmdlXtC a0MrjBa5VePDAmM/Hl1+tiMc8WOxOsYgxuTitBjBGDZM9F8PH+aEV/wFe0eHTg5qZvou2rAdG9o 54KW2 X-Received: by 2002:a05:6000:26cd:b0:435:a815:dd8d with SMTP id ffacd0b85a97d-43796b04f57mr32979736f8f.55.1771420719317; Wed, 18 Feb 2026 05:18:39 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260206182336.1397715-1-neelx@suse.com> <20260206182336.1397715-12-neelx@suse.com> <20260208153808.3476221-1-clm@meta.com> In-Reply-To: <20260208153808.3476221-1-clm@meta.com> From: Daniel Vacek Date: Wed, 18 Feb 2026 14:18:28 +0100 X-Gm-Features: AaiRm51fAAFTVBcqF-KI5-Lr8gaWIksaX5IH6JtEAzcWunIgDM49UiSlrdWV5YQ Message-ID: Subject: Re: [PATCH v6 11/43] btrfs: add inode encryption contexts To: Chris Mason Cc: Chris Mason , Josef Bacik , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Jens Axboe , David Sterba , linux-block@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Omar Sandoval , Sweet Tea Dorminy Content-Type: text/plain; charset="UTF-8" On Sun, 8 Feb 2026 at 16:38, Chris Mason wrote: > Daniel Vacek wrote: > > From: Omar Sandoval > > > > fscrypt stores a context item with encrypted inodes that contains the > > related encryption information. fscrypt provides an arbitrary blob for > > the filesystem to store, and it does not clearly fit into an existing > > structure, so this goes in a new item type. > > Hi everyone, > > I'm running the btrfs for-next branch, along with the encryption patch set > through my AI review prompts: > > https://github.com/masoncl/review-prompts > > I'm working on some btrfs specific instructions, but hopefully these reviews > are already useful. I've kept the headers to make it easier to double check > that I'm actually replying to the right email, but please let me know if any > parts of this are incorrect: > > commit 2d6114c2937b897d844735aa16d5369e3ec6d135 > Author: Omar Sandoval > > btrfs: add inode encryption contexts > > fscrypt stores a context item with encrypted inodes that contains the > related encryption information. fscrypt provides an arbitrary blob for > the filesystem to store, and it does not clearly fit into an existing > structure, so this goes in a new item type. > > > diff --git a/fs/btrfs/fscrypt.c b/fs/btrfs/fscrypt.c > > index 6cfba7d94e726..e9b024d671a22 100644 > > --- a/fs/btrfs/fscrypt.c > > +++ b/fs/btrfs/fscrypt.c > > [ ... ] > > > @@ -1,10 +1,126 @@ > > // SPDX-License-Identifier: GPL-2.0 > > > > +#include > > #include "ctree.h" > > +#include "accessors.h" > > #include "btrfs_inode.h" > > +#include "disk-io.h" > > +#include "fs.h" > > #include "fscrypt.h" > > +#include "ioctl.h" > > +#include "messages.h" > > +#include "transaction.h" > > +#include "xattr.h" > > + > > +static int btrfs_fscrypt_get_context(struct inode *inode, void *ctx, size_t len) > > +{ > > + struct btrfs_key key = { > > + .objectid = btrfs_ino(BTRFS_I(inode)), > > + .type = BTRFS_FSCRYPT_INODE_CTX_KEY, > > + .offset = 0, > > + }; > > + struct btrfs_path *path; > > + struct extent_buffer *leaf; > > + unsigned long ptr; > > + int ret; > > + > > + > > + path = btrfs_alloc_path(); > > + if (!path) > > + return -ENOMEM; > > + > > + ret = btrfs_search_slot(NULL, BTRFS_I(inode)->root, &key, path, 0, 0); > > + if (ret) { > > + len = -ENOENT; > > + goto out; > > + } > > + > > + leaf = path->nodes[0]; > > + ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); > > + /* fscrypt provides max context length, but it could be less */ > > + len = min_t(size_t, len, btrfs_item_size(leaf, path->slots[0])); > > + read_extent_buffer(leaf, ctx, ptr, len); > > + > > +out: > > + btrfs_free_path(path); > > + return len; > > +} > > + > > +static int btrfs_fscrypt_set_context(struct inode *inode, const void *ctx, > > + size_t len, void *fs_data) > > +{ > > + struct btrfs_trans_handle *trans = fs_data; > > + struct btrfs_key key = { > > + .objectid = btrfs_ino(BTRFS_I(inode)), > > + .type = BTRFS_FSCRYPT_INODE_CTX_KEY, > > + .offset = 0, > > + }; > > + struct btrfs_path *path = NULL; > > + struct extent_buffer *leaf; > > + unsigned long ptr; > > + int ret; > > + > > + if (!trans) > > + trans = btrfs_start_transaction(BTRFS_I(inode)->root, 2); > > + if (IS_ERR(trans)) > > + return PTR_ERR(trans); > > + > > + path = btrfs_alloc_path(); > > + if (!path) { > > + ret = -ENOMEM; > > + goto out_err; > > + } > > + > > + ret = btrfs_search_slot(trans, BTRFS_I(inode)->root, &key, path, 0, 1); > > + if (ret < 0) > > + goto out_err; > > + > > + if (ret > 0) { > > + btrfs_release_path(path); > > + ret = btrfs_insert_empty_item(trans, BTRFS_I(inode)->root, path, &key, len); > > + if (ret) > > + goto out_err; > > + } > > + > > + leaf = path->nodes[0]; > > + ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); > > + > > + len = min_t(size_t, len, btrfs_item_size(leaf, path->slots[0])); > > + write_extent_buffer(leaf, ctx, ptr, len); > > + btrfs_mark_buffer_dirty(trans, leaf); > > + btrfs_release_path(path); > > + > > + if (fs_data) > > + return ret; > > Does this code leak the path when fs_data is non-NULL? > > In btrfs_fscrypt_set_context(), a path is allocated via btrfs_alloc_path() > but when fs_data is provided (during inode creation with a transaction > handle), the function returns here without calling btrfs_free_path(path). > > The btrfs_release_path() call above only releases internal references to > extent buffers and locks but does not free the path structure itself. > > This leak occurs on every encrypted inode creation. The fix would be to add > btrfs_free_path(path) before the return. That's correct. Good catch! --- a/fs/btrfs/fscrypt.c +++ b/fs/btrfs/fscrypt.c @@ -155,7 +155,7 @@ static int btrfs_fscrypt_set_context(struct inode *inode, const void *ctx, btrfs_release_path(path); if (fs_data) - return ret; + goto out_err; BTRFS_I(inode)->flags |= BTRFS_INODE_ENCRYPT; btrfs_sync_inode_flags_to_i_flags(BTRFS_I(inode)); Thanks. --nX > > + > > + BTRFS_I(inode)->flags |= BTRFS_INODE_ENCRYPT; > > + btrfs_sync_inode_flags_to_i_flags(BTRFS_I(inode)); > > + inode_inc_iversion(inode); > > + inode_set_ctime_current(inode); > > + ret = btrfs_update_inode(trans, BTRFS_I(inode)); > > + if (ret) > > + goto out_abort; > > + btrfs_free_path(path); > > + btrfs_end_transaction(trans); > > + return 0; > > +out_abort: > > + btrfs_abort_transaction(trans, ret); > > +out_err: > > + if (!fs_data) > > + btrfs_end_transaction(trans); > > + btrfs_free_path(path); > > + return ret; > > +} > > [ ... ] >