Repository: moby/moby (language: go)

Issue:
BuildKit builder with inline cache causes daemon crash
### Description

After upgrading to Docker v23.0.0, most of my devcontainers and CI/CD pipelines stopped working.

After some investigation, I isolated the issue to the following command:

```console
$ echo "FROM ubuntu" | docker build . --build-arg BUILDKIT_INLINE_CACHE=1 -f-
[+] Building 1.6s (5/6)
 => [internal] load .dockerignore                                                                  0.0s
 => => transferring context: 2B                                                                    0.0s
 => [internal] load build definition from Dockerfile                                               0.0s
 => => transferring dockerfile: 49B                                                                0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                   1.6s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                      0.0s
 => CACHED [1/1] FROM docker.io/library/ubuntu@sha256:9a0bdde4188b896a372804be2384015e90e3f84906b  0.0s
 => preparing layers for inline cache                                                              0.0s
ERROR: failed to solve: Unavailable: error reading from server: EOF
```

I initially opened this issue in Buildkit repository, but as Docker daemon crashes, I decided to open it here instead. (https://github.com/moby/buildkit/issues/3576#issue-1569864216)

### Reproduce

```
echo "FROM ubuntu" | docker build . --build-arg BUILDKIT_INLINE_CACHE=1 -f-
```

### Expected behavior

To work as it worked before 23.0.0.

### docker version

```bash
Client: Docker Engine - Community
 Version:           23.0.0
 API version:       1.42
 Go version:        go1.19.5
 Git commit:        e92dd87
 Built:             Wed Feb  1 17:47:51 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.0
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.5
  Git commit:       d7573ab
  Built:            Wed Feb  1 17:47:51 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.16
  GitCommit:        31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
```


### docker info

```bash
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.2
    Path:     /home/felipecrs/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.15.1
    Path:     /home/felipecrs/.docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-scan

Server:
 Containers: 2
  Running: 0
  Paused: 0
  Stopped: 2
 Images: 6
 Server Version: 23.0.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.15.83.1-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 15.58GiB
 Name: FELIPE-MSI
 ID: EKD4:EAZA:6IFV:FFDZ:35NR:23ZD:3ZCV:QB72:T6BK:XVUF:Y6PT:JDWI
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
```


### Additional Info

I captured the following in my docker daemon logs:

Apparently, Docker daemon crashes.

```
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338482781-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338518578-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338541170-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338555858-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338572278-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338584261-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338615339-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338640275-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338670542-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338728350-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338784264-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338872399-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338904058-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.338913756-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.340002046-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.340055416-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348819671-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348849416-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348868752-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348875755-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348885013-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348891234-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348927542-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348958039-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.348979198-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.349030915-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.349072653-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.349177529-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.349210069-03:00" level=info msg="[c>
Feb 03 10:48:11 FELIPE-MSI dockerd[2622]: time="2023-02-03T10:48:11.349227412-03:00" level=info msg="[c>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: panic: runtime error: invalid memory address or nil pointer d>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: goroutine 694 [running]:
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: github.com/docker/docker/vendor/github.com/moby/buildkit/cach>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]:         /go/src/github.com/docker/docker/vendor/github.com/mo>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: github.com/docker/docker/vendor/github.com/moby/buildkit/util>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]:         /go/src/github.com/docker/docker/vendor/github.com/mo>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: sync.(*Once).doSlow(0x55aaad2bc885?, 0xa?)
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]:         /usr/local/go/src/sync/once.go:74 +0xc2
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: sync.(*Once).Do(0xc0014c8190?, 0xc0004ea000?)
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]:         /usr/local/go/src/sync/once.go:65 +0x1f
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]: created by github.com/docker/docker/vendor/github.com/moby/bu>
Feb 03 10:48:13 FELIPE-MSI dockerd[2622]:         /go/src/github.com/docker/docker/vendor/github.com/mo>
Feb 03 10:48:13 FELIPE-MSI systemd[1]: docker.service: Main process exited, code=exited, status=2/INVAL>
Feb 03 10:48:13 FELIPE-MSI systemd[1]: docker.service: Failed with result 'exit-code'.
Feb 03 10:48:15 FELIPE-MSI systemd[1]: docker.service: Scheduled restart job, restart counter is at 2.
Feb 03 10:48:15 FELIPE-MSI systemd[1]: Stopped Docker Application Container Engine.
Feb 03 10:48:15 FELIPE-MSI systemd[1]: Starting Docker Application Container Engine...
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.430026714-03:00" level=info msg="St>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.432788798-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.432818314-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.432845855-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.432859520-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.432974365-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433044977-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433111020-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433164089-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433193073-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433211447-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433587168-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.433634066-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434258752-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434288708-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434306501-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434333431-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434378816-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434403732-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434436143-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434456420-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434492628-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434526822-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434732636-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.434744658-03:00" level=info msg="[c>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.443321532-03:00" level=info msg="[g>
Feb 03 10:48:15 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:15.448322224-03:00" level=info msg="Lo>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.128413769-03:00" level=info msg="De>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.945982966-03:00" level=info msg="Lo>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.955400146-03:00" level=warning msg=>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.955431004-03:00" level=warning msg=>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.955435733-03:00" level=warning msg=>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.955438718-03:00" level=warning msg=>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.955450570-03:00" level=info msg="Do>
Feb 03 10:48:18 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:18.955473122-03:00" level=info msg="Da>
Feb 03 10:48:19 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:19.161730146-03:00" level=info msg="[c>
Feb 03 10:48:19 FELIPE-MSI systemd[1]: Started Docker Application Container Engine.
Feb 03 10:48:19 FELIPE-MSI dockerd[3648]: time="2023-02-03T10:48:19.164307827-03:00" level=info msg="AP>
li
```



Discussion / hints:
Thanks for your report. Looks to be related to inline cache.
We are also experiencing this, indeed with builds that use inline cache. Using registry cache works as a workaround. 

As it's cut off above, a more complete stacktrace:
```
    /go/src/github.com/docker/docker/vendor/github.com/moby/buildkit/util/flightcontrol/flightcontrol.go:164 +0x44a
created by github.com/docker/docker/vendor/github.com/moby/buildkit/util/flightcontrol.(*call).wait 
    /usr/local/go/src/sync/once.go:65 +0x1f 
sync.(*Once).Do(0xc00173f4a0?, 0xc00173f4b8?) 
    /usr/local/go/src/sync/once.go:74 +0xc2 
sync.(*Once).doSlow(0x1d3c485?, 0x2c841ea?)
    /go/src/github.com/docker/docker/vendor/github.com/moby/buildkit/util/flightcontrol/flightcontrol.go:121 +0x5e
github.com/docker/docker/vendor/github.com/moby/buildkit/util/flightcontrol.(*call).run(0xc000b727e0)
    /go/src/github.com/docker/docker/vendor/github.com/moby/buildkit/cache/blobs.go:224 +0x10e3
github.com/docker/docker/vendor/github.com/moby/buildkit/cache.computeBlobChain.func4.1({0xbdb078, 0xc0018a7ec0}) 
goroutine 3907 [running]: 
 
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x2e19203]
panic: runtime error: invalid memory address or nil pointer dereference
```

```
$ docker version
Client:
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 17:56:30 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          23.0.0
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.5
  Git commit:       d7573ab
  Built:            Wed Feb  1 17:46:24 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.16
  GitCommit:        31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
```
Hi, Experiencing the same issue after upgrading docker-machine with gitlab-runner for build using buildkit-inline-cache.
Docker v.23 is setup on the runner instance by default.

Fix patch:
diff --git a/.github/workflows/buildkit.yml b/.github/workflows/buildkit.yml
index 93fb09611e8ed..ba9b81aaddfea 100644
--- a/.github/workflows/buildkit.yml
+++ b/.github/workflows/buildkit.yml
@@ -70,9 +70,7 @@ jobs:
         name: BuildKit ref
         run: |
           echo "BUILDKIT_REPO=moby/buildkit" >> $GITHUB_ENV
-          # FIXME(thaJeztah) remove when updating BuildKit to v0.11.3
-          # echo "BUILDKIT_REF=$(./hack/buildkit-ref)" >> $GITHUB_ENV
-          echo "BUILDKIT_REF=09223a2c58d06e0333b48107be5490397d11e65a" >> $GITHUB_ENV
+          echo "BUILDKIT_REF=$(./hack/buildkit-ref)" >> $GITHUB_ENV
         working-directory: moby
       -
         name: Checkout BuildKit ${{ env.BUILDKIT_REF }}
diff --git a/builder/builder-next/worker/worker.go b/builder/builder-next/worker/worker.go
index 59934a2112347..d0c04ac605d0a 100644
--- a/builder/builder-next/worker/worker.go
+++ b/builder/builder-next/worker/worker.go
@@ -19,6 +19,7 @@ import (
 	"github.com/docker/docker/layer"
 	pkgprogress "github.com/docker/docker/pkg/progress"
 	"github.com/moby/buildkit/cache"
+	cacheconfig "github.com/moby/buildkit/cache/config"
 	"github.com/moby/buildkit/client"
 	"github.com/moby/buildkit/client/llb"
 	"github.com/moby/buildkit/executor"
@@ -37,7 +38,6 @@ import (
 	"github.com/moby/buildkit/source/http"
 	"github.com/moby/buildkit/source/local"
 	"github.com/moby/buildkit/util/archutil"
-	"github.com/moby/buildkit/util/compression"
 	"github.com/moby/buildkit/util/contentutil"
 	"github.com/moby/buildkit/util/progress"
 	"github.com/moby/buildkit/version"
@@ -86,6 +86,10 @@ type Worker struct {
 	SourceManager *source.Manager
 }
 
+var _ interface {
+	GetRemotes(context.Context, cache.ImmutableRef, bool, cacheconfig.RefConfig, bool, session.Group) ([]*solver.Remote, error)
+} = &Worker{}
+
 // NewWorker instantiates a local worker
 func NewWorker(opt Opt) (*Worker, error) {
 	sm, err := source.NewManager()
@@ -259,8 +263,11 @@ func (w *Worker) Exporter(name string, sm *session.Manager) (exporter.Exporter,
 	}
 }
 
-// GetRemote returns a remote snapshot reference for a local one
-func (w *Worker) GetRemote(ctx context.Context, ref cache.ImmutableRef, createIfNeeded bool, _ compression.Type, s session.Group) (*solver.Remote, error) {
+// GetRemotes returns the remote snapshot references given a local reference
+func (w *Worker) GetRemotes(ctx context.Context, ref cache.ImmutableRef, createIfNeeded bool, _ cacheconfig.RefConfig, all bool, s session.Group) ([]*solver.Remote, error) {
+	if ref == nil {
+		return nil, nil
+	}
 	var diffIDs []layer.DiffID
 	var err error
 	if !createIfNeeded {
@@ -290,10 +297,10 @@ func (w *Worker) GetRemote(ctx context.Context, ref cache.ImmutableRef, createIf
 		}
 	}
 
-	return &solver.Remote{
+	return []*solver.Remote{{
 		Descriptors: descriptors,
 		Provider:    &emptyProvider{},
-	}, nil
+	}}, nil
 }
 
 // PruneCacheMounts removes the current cache snapshots for specified IDs
diff --git a/vendor.mod b/vendor.mod
index 48812e7b858bf..562a4b53f861b 100644
--- a/vendor.mod
+++ b/vendor.mod
@@ -56,7 +56,7 @@ require (
 	github.com/klauspost/compress v1.15.12
 	github.com/miekg/dns v1.1.43
 	github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible
-	github.com/moby/buildkit v0.11.2 // FIXME(thaJeztah): remove override from .github/workflows/buildkit.yml when updating to v0.11.3
+	github.com/moby/buildkit v0.11.3-0.20230206194711-49992f513921
 	github.com/moby/ipvs v1.1.0
 	github.com/moby/locker v1.0.1
 	github.com/moby/patternmatcher v0.5.0
diff --git a/vendor.sum b/vendor.sum
index 77b0674eb3209..d218304cb9b22 100644
--- a/vendor.sum
+++ b/vendor.sum
@@ -754,8 +754,8 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu
 github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
 github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
 github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
-github.com/moby/buildkit v0.11.2 h1:hNNsYuRssvFnp/qJ8FifStEUzROl5riPAEwk7cRzMjg=
-github.com/moby/buildkit v0.11.2/go.mod h1:b5hR8j3BZaOj5+gf6yielP9YLT9mU92zy3zZtdoUTrw=
+github.com/moby/buildkit v0.11.3-0.20230206194711-49992f513921 h1:B6x+BCRpTTUhEsHtvBpi2IsRnrLCJ7xoJ3oZrO8oQEU=
+github.com/moby/buildkit v0.11.3-0.20230206194711-49992f513921/go.mod h1:P8MqGq7YrIDldCdZLhK8M/vPcrFYZ6GX1crX0j4hOmQ=
 github.com/moby/ipvs v1.1.0 h1:ONN4pGaZQgAx+1Scz5RvWV4Q7Gb+mvfRh3NsPS+1XQQ=
 github.com/moby/ipvs v1.1.0/go.mod h1:4VJMWuf098bsUMmZEiD4Tjk/O7mOn3l1PTD3s4OoYAs=
 github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
diff --git a/vendor/github.com/moby/buildkit/cache/remotecache/inline/inline.go b/vendor/github.com/moby/buildkit/cache/remotecache/inline/inline.go
index 59631a9d5491a..036ec059f76e2 100644
--- a/vendor/github.com/moby/buildkit/cache/remotecache/inline/inline.go
+++ b/vendor/github.com/moby/buildkit/cache/remotecache/inline/inline.go
@@ -56,16 +56,20 @@ func (ce *exporter) ExportForLayers(ctx context.Context, layers []digest.Digest)
 		return nil, err
 	}
 
+	layerBlobDigests := make([]digest.Digest, len(layers))
+
 	descs2 := map[digest.Digest]v1.DescriptorProviderPair{}
-	for _, k := range layers {
+	for i, k := range layers {
 		if v, ok := descs[k]; ok {
 			descs2[k] = v
+			layerBlobDigests[i] = k
 			continue
 		}
 		// fallback for uncompressed digests
 		for _, v := range descs {
 			if uc := v.Descriptor.Annotations["containerd.io/uncompressed"]; uc == string(k) {
 				descs2[v.Descriptor.Digest] = v
+				layerBlobDigests[i] = v.Descriptor.Digest
 			}
 		}
 	}
@@ -87,7 +91,7 @@ func (ce *exporter) ExportForLayers(ctx context.Context, layers []digest.Digest)
 
 	// reorder layers based on the order in the image
 	blobIndexes := make(map[digest.Digest]int, len(layers))
-	for i, blob := range layers {
+	for i, blob := range layerBlobDigests {
 		blobIndexes[blob] = i
 	}
 
diff --git a/vendor/modules.txt b/vendor/modules.txt
index f0038410f7758..ff416c54f2fa0 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -540,7 +540,7 @@ github.com/mistifyio/go-zfs
 # github.com/mitchellh/hashstructure/v2 v2.0.2
 ## explicit; go 1.14
 github.com/mitchellh/hashstructure/v2
-# github.com/moby/buildkit v0.11.2
+# github.com/moby/buildkit v0.11.3-0.20230206194711-49992f513921
 ## explicit; go 1.18
 github.com/moby/buildkit/api/services/control
 github.com/moby/buildkit/api/types


Test patch: