Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while marshaling: string field contains invalid UTF-8 #467

Open
shollingsworth opened this issue Jul 28, 2021 · 4 comments
Open

error while marshaling: string field contains invalid UTF-8 #467

shollingsworth opened this issue Jul 28, 2021 · 4 comments
Milestone

Comments

@shollingsworth
Copy link
Contributor

Hello there,

Found a bug with a specific program (an interesting one IMO)

[2021-07-28 16:21:19]  ERR  Invalid rule received, applying default action
[2021-07-28 16:21:19]  WAR  Error while pinging UI service: rpc error: code = Internal desc = grpc: error while marshaling: string field contains invalid UTF-8, state: READY

To Reproduce

  • Install the package sqsh (a mssql client) on Ubuntu 20.04
  • Connect to a non existent server (in this case localhost)
  • OK interaction
    Prompt should popup after typing in password
sqsh -S localhost
  • Error interaction
sqsh -S localhost -P foo

Screenshots

OK Interaction

ok_interaction

Error Interaction

bad_interaction

OS (please complete the following information):

  • OS: NAME="Ubuntu" VERSION="20.04.2 LTS (Focal Fossa)"
  • Kernel: Linux X 5.10.0-1034-oem 35-Ubuntu SMP Wed Jun 23 09:55:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Window Manager: KDE
@gustavo-iniguez-goya
Copy link
Collaborator

good catch @shollingsworth !

I'll try to reproduce it.

@gustavo-iniguez-goya
Copy link
Collaborator

ok, reproduced, even with eBPF.

It's invoked correctly:
execve("/usr/bin/sqsh", ["sqsh", "-S", "localhost", "-P", "sss"], 0x7ffe74bb4da0 /* 58 vars */) = 0

But sqsh rewrites in memory the parameter -P:
https://github.com/vonloxley/sqsh/blob/afd4276e09d5dfdd5873d6db62a81dfeff9eded9/src/sqsh_main.c#L1083

execve("/usr/local/bin/sqsh", ["sqsh", "-S", "localhost", "-\2503/4"], 0x7ffec415d0b8 /* 58 vars */) = -1 ENOENT 
execve("/usr/bin/sqsh", ["sqsh", "-S", "localhost", "-\2503/4"], 0x7ffec415d0b8 /* 58 vars */) = 0
$ cat /proc/10915/cmdline 
sqsh-Slocalhost-�3/4

execsnoop-bpfcc catches correctly the original command line:

PCOMM            PID    PPID   RET ARGS
sqsh             23765  4335     0 /usr/bin/sqsh -S localhost -P sss
sqsh             23765  4335     0 /usr/bin/sqsh -S localhost -�3/4

But when we read the command line of the PID, I can't recover the unmodified parameter. We should get it from kernel space (bpf_probe_read_kernel_str(&data4.path1, sizeof(data4.path1), &task->mm->exe_file->f_path.dentry->d_parent->d_parent->d_name.name);), or if it's not possible due to hit the 512bytes limit, maybe we could workaround it by maintaining a map of new execs.

Rewriting the arguments and name of your own process is a valid and expected operation, so we shouldn't trust what's written to /proc

So far I haven't found a way to workaround this problem. strconv.IsPrint() and utf8.ValidRune() report "�3/4" as valid, while utf8.Valid() reports it as invalid, but also "ááá" ... so any parameters with unicode chars would be rewritten.

@shollingsworth
Copy link
Contributor Author

Thanks for doing the digging on this @gustavo-iniguez-goya , I'm guessing we can just close this as a one off if there's no easy fix.

@gustavo-iniguez-goya gustavo-iniguez-goya added this to the 1.5.0 milestone Jul 29, 2021
@gustavo-iniguez-goya
Copy link
Collaborator

I think the best solution will be to encode the parameters. I've got it working but it needs more work to ensure that everything is working properly (note: encode parameters when loading rules).

utf8, graphics and other encodings seems to work fine, so I'll postpone this issue for the next version

image

@gustavo-iniguez-goya gustavo-iniguez-goya modified the milestones: 1.5.0, 1.6.0 Jan 26, 2022
@gustavo-iniguez-goya gustavo-iniguez-goya modified the milestones: 1.6.0, 1.7.0 May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants