mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] ecryptfs leaks an inode on lookup failure -> kernel BUG in generic_shutdown_super()
@ 2026-08-28  3:18 Farhad Alemi
  2026-08-28 16:57 ` Tyler Hicks
  0 siblings, 1 reply; 3+ messages in thread
From: Farhad Alemi @ 2026-08-28  3:18 UTC (permalink / raw)
  To: Tyler Hicks, Alexander Viro, Christian Brauner
  Cc: falemi, ecryptfs, linux-fsdevel, linux-kernel

Hello,

As part of the kernel research at ASU's SEFCOM
lab, we hit the crash below. Crash reports can be found here:

  https://github.com/farhad-alemi/public_bug_reports/tree/main/128-ecryptfs-i_new-inode-leak-lookup-failure/

  ecryptfs_i_size_read: Error attempting to initialize the lower file
for the dentry with name [victim]; rc = [-26]
  VFS: Busy inodes after unmount of ecryptfs (ecryptfs)
  kernel BUG at fs/super.c:779!
  Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
  Call Trace:
   kill_anon_super+0x3b/0x70
   ecryptfs_kill_block_super+0x44/0xa0
   deactivate_locked_super+0xbc/0x110
   cleanup_mnt+0x437/0x4d0
   task_work_run+0x1d9/0x270
   exit_to_user_mode_loop+0x14e/0x540
   do_syscall_64+0x317/0x510
  Kernel panic - not syncing: Fatal exception

Our reproducer.c is available upon request.

Happy to test a patch if that would help.

Regards,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] ecryptfs leaks an inode on lookup failure -> kernel BUG in generic_shutdown_super()
  2026-08-28  3:18 [BUG] ecryptfs leaks an inode on lookup failure -> kernel BUG in generic_shutdown_super() Farhad Alemi
@ 2026-08-28 16:57 ` Tyler Hicks
  2026-09-08  4:50   ` Farhad Alemi
  0 siblings, 1 reply; 3+ messages in thread
From: Tyler Hicks @ 2026-08-28 16:57 UTC (permalink / raw)
  To: Farhad Alemi
  Cc: Alexander Viro, Christian Brauner, falemi, ecryptfs,
	linux-fsdevel, linux-kernel

On 2026-08-27 20:18:11, Farhad Alemi wrote:
> Hello,

Hi - Thank you for the report.

> As part of the kernel research at ASU's SEFCOM
> lab, we hit the crash below. Crash reports can be found here:
> 
>   https://github.com/farhad-alemi/public_bug_reports/tree/main/128-ecryptfs-i_new-inode-leak-lookup-failure/
> 
>   ecryptfs_i_size_read: Error attempting to initialize the lower file
> for the dentry with name [victim]; rc = [-26]
>   VFS: Busy inodes after unmount of ecryptfs (ecryptfs)
>   kernel BUG at fs/super.c:779!
>   Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
>   Call Trace:
>    kill_anon_super+0x3b/0x70
>    ecryptfs_kill_block_super+0x44/0xa0
>    deactivate_locked_super+0xbc/0x110
>    cleanup_mnt+0x437/0x4d0
>    task_work_run+0x1d9/0x270
>    exit_to_user_mode_loop+0x14e/0x540
>    do_syscall_64+0x317/0x510
>   Kernel panic - not syncing: Fatal exception
> 
> Our reproducer.c is available upon request.

Yes, please provide reproducer.c.

Tyler

> Happy to test a patch if that would help.
> 
> Regards,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] ecryptfs leaks an inode on lookup failure -> kernel BUG in generic_shutdown_super()
  2026-08-28 16:57 ` Tyler Hicks
@ 2026-09-08  4:50   ` Farhad Alemi
  0 siblings, 0 replies; 3+ messages in thread
From: Farhad Alemi @ 2026-09-08  4:50 UTC (permalink / raw)
  To: Tyler Hicks; +Cc: ecryptfs, linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1274 bytes --]

Apologies for the delayed response; reproducer attached! Thanks!

On Fri, Aug 28, 2026 at 9:57 AM Tyler Hicks <code@tyhicks.com> wrote:
>
> On 2026-08-27 20:18:11, Farhad Alemi wrote:
> > Hello,
>
> Hi - Thank you for the report.
>
> > As part of the kernel research at ASU's SEFCOM
> > lab, we hit the crash below. Crash reports can be found here:
> >
> >   https://github.com/farhad-alemi/public_bug_reports/tree/main/128-ecryptfs-i_new-inode-leak-lookup-failure/
> >
> >   ecryptfs_i_size_read: Error attempting to initialize the lower file
> > for the dentry with name [victim]; rc = [-26]
> >   VFS: Busy inodes after unmount of ecryptfs (ecryptfs)
> >   kernel BUG at fs/super.c:779!
> >   Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
> >   Call Trace:
> >    kill_anon_super+0x3b/0x70
> >    ecryptfs_kill_block_super+0x44/0xa0
> >    deactivate_locked_super+0xbc/0x110
> >    cleanup_mnt+0x437/0x4d0
> >    task_work_run+0x1d9/0x270
> >    exit_to_user_mode_loop+0x14e/0x540
> >    do_syscall_64+0x317/0x510
> >   Kernel panic - not syncing: Fatal exception
> >
> > Our reproducer.c is available upon request.
>
> Yes, please provide reproducer.c.
>
> Tyler
>
> > Happy to test a patch if that would help.
> >
> > Regards,

[-- Attachment #2: reproducer.c --]
[-- Type: application/octet-stream, Size: 4174 bytes --]

/*
 * Reproducer for 128-ecryptfs-i_new-inode-leak-lookup-failure
 *
 * Build: gcc -static -O0 -w -o repro reproducer.c
 * Run:   as root, in a disposable VM. It is expected to panic the kernel.
 */
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>

#define WORK_DIR   "/ecwork"
#define LOWER_DIR  WORK_DIR "/lower"
#define UPPER_DIR  WORK_DIR "/top"
#define VICTIM     LOWER_DIR "/victim"

/* "sig=" is memcmp'd over ECRYPTFS_SIG_SIZE_HEX bytes and is also the
 * description of the "user" key that ecryptfs request_key()s */
#define KEY_SIG "0123456789abcdef"

#define ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES 512
#define ECRYPTFS_MAX_KEY_BYTES 64
#define ECRYPTFS_SALT_SIZE 8
#define ECRYPTFS_PASSWORD_SIG_SIZE 16

struct ecryptfs_session_key {
	unsigned int flags;
	unsigned int encrypted_key_size;
	unsigned int decrypted_key_size;
	unsigned char encrypted_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES];
	unsigned char decrypted_key[ECRYPTFS_MAX_KEY_BYTES];
};

struct ecryptfs_password {
	unsigned int password_bytes;
	int hash_algo;
	unsigned int hash_iterations;
	unsigned int session_key_encryption_key_bytes;
	unsigned int flags;
	unsigned char session_key_encryption_key[ECRYPTFS_MAX_KEY_BYTES];
	unsigned char signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1];
	unsigned char salt[ECRYPTFS_SALT_SIZE];
};

/* 740 bytes on x86_64; ecryptfs validates the payload size */
struct ecryptfs_auth_tok {
	unsigned short version;
	unsigned short token_type;
	unsigned int flags;
	struct ecryptfs_session_key session_key;
	unsigned char reserved[32];
	union {
		struct ecryptfs_password password;
	} token;
} __attribute__((packed));

static int add_ecryptfs_auth_tok_key(void)
{
	struct ecryptfs_auth_tok auth_tok;

	memset(&auth_tok, 0, sizeof(auth_tok));
	auth_tok.version = 0x0004;
	auth_tok.token_type = 0;			/* ECRYPTFS_PASSWORD */
	auth_tok.token.password.password_bytes = 16;
	auth_tok.token.password.hash_iterations = 1;
	auth_tok.token.password.session_key_encryption_key_bytes = 16;
	auth_tok.token.password.flags = 0x02;	/* SESSION_KEY_ENCRYPTION_KEY_SET */
	memset(auth_tok.token.password.session_key_encryption_key, 0x41, 16);
	memcpy(auth_tok.token.password.signature, KEY_SIG, 16);

	return syscall(__NR_add_key, "user", KEY_SIG, &auth_tok,
		       sizeof(auth_tok), -3 /* KEY_SPEC_SESSION_KEYRING */) < 0;
}

static int copy_self_to_victim(void)
{
	char buf[65536];
	int self_fd = open("/proc/self/exe", O_RDONLY);
	int victim_fd = open(VICTIM, O_RDWR | O_CREAT | O_TRUNC, 0755);
	ssize_t n;

	if (self_fd < 0 || victim_fd < 0)
		return 1;
	while ((n = read(self_fd, buf, sizeof(buf))) > 0)
		if (write(victim_fd, buf, n) != n)
			return 1;
	close(self_fd);
	close(victim_fd);
	return chmod(VICTIM, 0755);
}

int main(int argc, char **argv)
{
	struct stat stat_buf;

	/* re-exec'ed as the process that keeps VICTIM busy */
	if (argc > 1)
		for (;;)
			pause();

	mkdir(WORK_DIR, 0777);
	mount("none", WORK_DIR, "tmpfs", 0, "");
	mkdir(LOWER_DIR, 0777);
	mkdir(UPPER_DIR, 0777);

	if (copy_self_to_victim()) {
		printf("cannot stage %s: %s\n", VICTIM, strerror(errno));
		return 1;
	}

	/* Executing VICTIM makes deny_write_access() refuse every later
	 * O_RDWR open of it with -ETXTBSY -- including the one ecryptfs'
	 * privileged kthread does, which is what makes the lookup fail. */
	if (fork() == 0) {
		char *argv_sleeper[] = { (char *)"victim", (char *)"busy", NULL };
		execv(VICTIM, argv_sleeper);
		_exit(127);
	}
	sleep(1);

	if (add_ecryptfs_auth_tok_key()) {
		printf("add_key: %s\n", strerror(errno));
		return 1;
	}
	if (mount(LOWER_DIR, UPPER_DIR, "ecryptfs", 0,
		  "sig=" KEY_SIG ",cipher=aes,ecryptfs_key_bytes=16")) {
		printf("ecryptfs mount: %s\n", strerror(errno));
		return 1;
	}

	/* ecryptfs_lookup_interpose() -> ecryptfs_i_size_read() fails, and its
	 * error path returns without unlock_new_inode() and without iput(), so
	 * this I_NEW inode stays on sb->s_inodes. */
	stat(UPPER_DIR "/victim", &stat_buf);

	/* the leaked inode is still there: busy-inode check -> BUG() */
	umount2(UPPER_DIR, 0);
	return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-08  4:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-28  3:18 [BUG] ecryptfs leaks an inode on lookup failure -> kernel BUG in generic_shutdown_super() Farhad Alemi
2026-08-28 16:57 ` Tyler Hicks
2026-09-08  4:50   ` Farhad Alemi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®