All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Log if a core dump is aborted due to changed file permissions
@ 2021-07-01 23:31 David Oberhollenzer
  2021-08-02 20:47 ` David Oberhollenzer
  2021-08-02 21:40 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: David Oberhollenzer @ 2021-07-01 23:31 UTC (permalink / raw)
  To: viro, linux-fsdevel, linux-kernel; +Cc: richard, David Oberhollenzer

For obvious security reasons, a core dump is aborted if the
filesystem cannot preserve ownership or permissions of the
dump file.

This affects filesystems like e.g. vfat, but also something like
a 9pfs share in a Qemu test setup, running as a regular user,
depending on the security model used. In those cases, the result
is an empty core file and a confused user.

To hopefully safe other people a lot of time figuring out the
cause, this patch adds a simple log message for those specific
cases.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 fs/coredump.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index c3d8fc14b993..3e53d3e18b0e 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -782,10 +777,17 @@ void do_coredump(const kernel_siginfo_t *siginfo)
 		 * filesystem.
 		 */
 		mnt_userns = file_mnt_user_ns(cprm.file);
-		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode), current_fsuid()))
+		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode),
+			    current_fsuid())) {
+			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file owner\n",
+					    cn.corename);
 			goto close_fail;
-		if ((inode->i_mode & 0677) != 0600)
+		}
+		if ((inode->i_mode & 0677) != 0600) {
+			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file permissions\n",
+					    cn.corename);
 			goto close_fail;
+		}
 		if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
 			goto close_fail;
 		if (do_truncate(mnt_userns, cprm.file->f_path.dentry,
-- 
2.31.1


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

* Re: [PATCH] Log if a core dump is aborted due to changed file permissions
  2021-07-01 23:31 [PATCH] Log if a core dump is aborted due to changed file permissions David Oberhollenzer
@ 2021-08-02 20:47 ` David Oberhollenzer
  2021-08-02 21:40 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: David Oberhollenzer @ 2021-08-02 20:47 UTC (permalink / raw)
  To: viro, linux-fsdevel, linux-kernel; +Cc: richard, Andrew Morton

Friendly ping :-)

On 7/2/21 1:31 AM, David Oberhollenzer wrote:
> For obvious security reasons, a core dump is aborted if the
> filesystem cannot preserve ownership or permissions of the
> dump file.
>
> This affects filesystems like e.g. vfat, but also something like
> a 9pfs share in a Qemu test setup, running as a regular user,
> depending on the security model used. In those cases, the result
> is an empty core file and a confused user.
>
> To hopefully safe other people a lot of time figuring out the
> cause, this patch adds a simple log message for those specific
> cases.
>
> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
> ---
>   fs/coredump.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index c3d8fc14b993..3e53d3e18b0e 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -782,10 +777,17 @@ void do_coredump(const kernel_siginfo_t *siginfo)
>   		 * filesystem.
>   		 */
>   		mnt_userns = file_mnt_user_ns(cprm.file);
> -		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode), current_fsuid()))
> +		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode),
> +			    current_fsuid())) {
> +			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file owner\n",
> +					    cn.corename);
>   			goto close_fail;
> -		if ((inode->i_mode & 0677) != 0600)
> +		}
> +		if ((inode->i_mode & 0677) != 0600) {
> +			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file permissions\n",
> +					    cn.corename);
>   			goto close_fail;
> +		}
>   		if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
>   			goto close_fail;
>   		if (do_truncate(mnt_userns, cprm.file->f_path.dentry,
> --
> 2.31.1
>



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

* Re: [PATCH] Log if a core dump is aborted due to changed file permissions
  2021-07-01 23:31 [PATCH] Log if a core dump is aborted due to changed file permissions David Oberhollenzer
  2021-08-02 20:47 ` David Oberhollenzer
@ 2021-08-02 21:40 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2021-08-02 21:40 UTC (permalink / raw)
  To: David Oberhollenzer; +Cc: viro, linux-fsdevel, linux-kernel, richard

On Fri,  2 Jul 2021 01:31:51 +0200 David Oberhollenzer <david.oberhollenzer@sigma-star.at> wrote:

> For obvious security reasons, a core dump is aborted if the
> filesystem cannot preserve ownership or permissions of the
> dump file.
> 
> This affects filesystems like e.g. vfat, but also something like
> a 9pfs share in a Qemu test setup, running as a regular user,
> depending on the security model used. In those cases, the result
> is an empty core file and a confused user.
> 
> To hopefully safe other people a lot of time figuring out the
> cause, this patch adds a simple log message for those specific
> cases.

Seems sane.

> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -782,10 +777,17 @@ void do_coredump(const kernel_siginfo_t *siginfo)
>  		 * filesystem.
>  		 */
>  		mnt_userns = file_mnt_user_ns(cprm.file);
> -		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode), current_fsuid()))
> +		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode),
> +			    current_fsuid())) {
> +			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file owner\n",

But why the "|%s"?  This signifies dump-to-pipe, yes?  Don't we need
the below?

--- a/fs/coredump.c~log-if-a-core-dump-is-aborted-due-to-changed-file-permissions-fix
+++ a/fs/coredump.c
@@ -784,12 +784,12 @@ void do_coredump(const kernel_siginfo_t
 		mnt_userns = file_mnt_user_ns(cprm.file);
 		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode),
 			    current_fsuid())) {
-			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file owner\n",
+			pr_info_ratelimited("Core dump to %s aborted: cannot preserve file owner\n",
 					    cn.corename);
 			goto close_fail;
 		}
 		if ((inode->i_mode & 0677) != 0600) {
-			pr_info_ratelimited("Core dump to |%s aborted: cannot preserve file permissions\n",
+			pr_info_ratelimited("Core dump to %s aborted: cannot preserve file permissions\n",
 					    cn.corename);
 			goto close_fail;
 		}
_


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

end of thread, other threads:[~2021-08-02 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 23:31 [PATCH] Log if a core dump is aborted due to changed file permissions David Oberhollenzer
2021-08-02 20:47 ` David Oberhollenzer
2021-08-02 21:40 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.