|
| 1 | +From 4745215cea5eb7927e2ff37a57124c91355f1bd7 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Tue, 13 May 2025 08:36:18 -0400 |
| 4 | +Subject: [PATCH] Address CVE-2025-0495 |
| 5 | +Upstream Patch Reference: https://github.com/docker/buildx/commit/0982070af84d476b232d2d75ab551c3222592db1 |
| 6 | + |
| 7 | +--- |
| 8 | + commands/bake.go | 12 +++++++++++- |
| 9 | + commands/build.go | 7 ++++++- |
| 10 | + util/tracing/trace.go | 7 +++---- |
| 11 | + 3 files changed, 20 insertions(+), 6 deletions(-) |
| 12 | + |
| 13 | +diff --git a/commands/bake.go b/commands/bake.go |
| 14 | +index 129b635..a3fa1ac 100644 |
| 15 | +--- a/commands/bake.go |
| 16 | ++++ b/commands/bake.go |
| 17 | +@@ -5,6 +5,7 @@ import ( |
| 18 | + "encoding/json" |
| 19 | + "fmt" |
| 20 | + "os" |
| 21 | ++ "strings" |
| 22 | + |
| 23 | + "github.com/containerd/containerd/platforms" |
| 24 | + "github.com/docker/buildx/bake" |
| 25 | +@@ -17,6 +18,7 @@ import ( |
| 26 | + "github.com/moby/buildkit/util/appcontext" |
| 27 | + "github.com/pkg/errors" |
| 28 | + "github.com/spf13/cobra" |
| 29 | ++ "go.opentelemetry.io/otel/attribute" |
| 30 | + ) |
| 31 | + |
| 32 | + type bakeOptions struct { |
| 33 | +@@ -29,7 +31,15 @@ type bakeOptions struct { |
| 34 | + func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error) { |
| 35 | + ctx := appcontext.Context() |
| 36 | + |
| 37 | +- ctx, end, err := tracing.TraceCurrentCommand(ctx, "bake") |
| 38 | ++ // Convert slices to strings |
| 39 | ++ targetsStr := strings.Join(targets, ",") |
| 40 | ++ filesStr := strings.Join(in.files, ",") |
| 41 | ++ |
| 42 | ++ ctx, end, err := tracing.TraceCurrentCommand(ctx, append([]string{"bake"}, targets...), |
| 43 | ++ attribute.String("builder", in.commonOptions.builder), |
| 44 | ++ attribute.String("targets", targetsStr), |
| 45 | ++ attribute.String("files", filesStr), |
| 46 | ++ ) |
| 47 | + if err != nil { |
| 48 | + return err |
| 49 | + } |
| 50 | +diff --git a/commands/build.go b/commands/build.go |
| 51 | +index bfefd70..be6a41e 100644 |
| 52 | +--- a/commands/build.go |
| 53 | ++++ b/commands/build.go |
| 54 | +@@ -26,6 +26,7 @@ import ( |
| 55 | + "github.com/sirupsen/logrus" |
| 56 | + "github.com/spf13/cobra" |
| 57 | + "github.com/spf13/pflag" |
| 58 | ++ "go.opentelemetry.io/otel/attribute" |
| 59 | + ) |
| 60 | + |
| 61 | + const defaultTargetName = "default" |
| 62 | +@@ -72,7 +73,11 @@ type commonOptions struct { |
| 63 | + func runBuild(dockerCli command.Cli, in buildOptions) (err error) { |
| 64 | + ctx := appcontext.Context() |
| 65 | + |
| 66 | +- ctx, end, err := tracing.TraceCurrentCommand(ctx, "build") |
| 67 | ++ ctx, end, err := tracing.TraceCurrentCommand(ctx, []string{"build", in.contextPath}, |
| 68 | ++ attribute.String("builder", in.builder), |
| 69 | ++ attribute.String("context", in.contextPath), |
| 70 | ++ attribute.String("dockerfile", in.dockerfileName), |
| 71 | ++ ) |
| 72 | + if err != nil { |
| 73 | + return err |
| 74 | + } |
| 75 | +diff --git a/util/tracing/trace.go b/util/tracing/trace.go |
| 76 | +index c95ad5a..13ce349 100644 |
| 77 | +--- a/util/tracing/trace.go |
| 78 | ++++ b/util/tracing/trace.go |
| 79 | +@@ -2,7 +2,6 @@ package tracing |
| 80 | + |
| 81 | + import ( |
| 82 | + "context" |
| 83 | +- "os" |
| 84 | + "strings" |
| 85 | + |
| 86 | + "github.com/moby/buildkit/util/tracing/detect" |
| 87 | +@@ -10,13 +9,13 @@ import ( |
| 88 | + "go.opentelemetry.io/otel/trace" |
| 89 | + ) |
| 90 | + |
| 91 | +-func TraceCurrentCommand(ctx context.Context, name string) (context.Context, func(error), error) { |
| 92 | ++func TraceCurrentCommand(ctx context.Context, args []string, attrs ...attribute.KeyValue) (context.Context, func(error), error) { |
| 93 | + tp, err := detect.TracerProvider() |
| 94 | + if err != nil { |
| 95 | + return context.Background(), nil, err |
| 96 | + } |
| 97 | +- ctx, span := tp.Tracer("").Start(ctx, name, trace.WithAttributes( |
| 98 | +- attribute.String("command", strings.Join(os.Args, " ")), |
| 99 | ++ ctx, span := tp.Tracer("").Start(ctx, strings.Join(args, " "), trace.WithAttributes( |
| 100 | ++ attrs..., |
| 101 | + )) |
| 102 | + |
| 103 | + return ctx, func(err error) { |
| 104 | +-- |
| 105 | +2.34.1 |
| 106 | + |
0 commit comments