EC Audit: N2: storage node panics when another node answers an EC part request with a linker header of huge payload length
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 64/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- go
調査の方向性
Start with the linker allocation sites in pkg/services/object/get/ec.go at the full GET and ranged GET paths, then read InitGetObjectStream in pkg/services/object/get/util.go to understand the unverified header. Add or adapt a regression test in pkg/services/object/get/ using a LINK header with an oversized declared payload. Done means both GET paths reject or safely bound the payload without panicking or allocating based on its declared length.
索引モデルが issue の本文から書いたものです。
説明
Expected Behavior
A header received from another node cannot make the node allocate an arbitrary amount of memory. A bad reply fails that one request.
Current Behavior
When the reply to an EC part request is an object of type LINK, the node allocates a buffer of the payload length declared in the received header, before any check of that header:
- full GET: get/ec.go#L598-L599
- ranged GET: get/ec.go#L1025-L1026
The header comes from InitGetObjectStream, which asks the SDK client to skip verification (get/util.go#L330-L332). The only check before the allocation is that the parent ID field equals the requested ID (get/ec.go#L676-L683). verifyParentHeaderID from #4290 is placed after the linker branch on purpose and does not apply to it.
With PayloadSize = 1<<62 in the reply, make panics with makeslice: len out of range. On the full GET path this happens in an errgroup goroutine; nothing in the node recovers panics, so the process exits. Smaller values that pass make allocate that much memory.
The reply has to come from a node of the container, that is, from a faulty or hostile storage node. In the gRPC handler the full GET first goes through the streaming transport, which reports a LINK first part as ErrLinker and then falls back to this code (get/ec.go#L197-L203).
For non-linker parts the allocation at get/ec.go#L619-L627 is now bounded by the payload size of a parent header that hashes to the requested ID, which is fine for real objects.
Possible Solution
Bound the linker's payload length before allocating: a linker of an object cannot be longer than the network's MaxObjectSize, and a tighter bound follows from the number of children. Reading through io.LimitReader into a growing buffer avoids trusting the declared length at all.
Steps to Reproduce (for bugs)
- Save the test below as
pkg/services/object/get/ecaudit_test.go. go test ./pkg/services/object/get/ -run 'TestECAuditN2/ranged' -vpasses: it asserts the panic.go test ./pkg/services/object/get/ -run 'TestECAuditN2/full' -vkills the test binary:
panic: runtime error: makeslice: len out of range
goroutine 14 [running]:
…/pkg/services/object/get/ec.go:599 +0x228
…/pkg/services/object/get/ec.go:404 +0xb0
ecaudit_test.go
package getsvc
import (
"bytes"
"context"
"crypto/ecdsa"
"io"
"testing"
iec "github.com/nspcc-dev/neofs-node/internal/ec"
"github.com/nspcc-dev/neofs-node/internal/testutil"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
neofscryptotest "github.com/nspcc-dev/neofs-sdk-go/crypto/test"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
"github.com/stretchr/testify/require"
)
type ecAuditScene struct {
cnr cid.ID
rule iec.Rule
parentHdr object.Object
parentAddr oid.Address
parentPayload []byte
partObjs []object.Object
nodeSvcs []*Service
nodeLists [][]netmap.NodeInfo
getNodesMap map[oid.Address]getNodesForObjectValue
tc *testECServiceConn
}
func newECAuditScene(t *testing.T, rule iec.Rule, pldLen int) *ecAuditScene {
s := &ecAuditScene{cnr: cidtest.ID(), rule: rule, parentPayload: testutil.RandByteSlice(pldLen)}
s.parentHdr.SetContainerID(s.cnr)
s.parentHdr.SetPayloadSize(uint64(pldLen))
require.NoError(t, s.parentHdr.CalculateAndSetID())
s.parentAddr = oid.NewAddress(s.cnr, s.parentHdr.GetID())
parts, _, err := iec.Encode(rule, s.parentPayload)
require.NoError(t, err)
s.partObjs = make([]object.Object, len(parts))
for i := range parts {
s.partObjs[i], err = iec.FormObjectForECPart(usertest.User(), s.parentHdr, parts[i], iec.PartInfo{Index: i})
require.NoError(t, err)
}
s.nodeLists, _ = testNodeMatrix(t, []int{len(parts)})
s.getNodesMap = map[oid.Address]getNodesForObjectValue{
s.parentAddr: {nodeSets: s.nodeLists, ecRules: []iec.Rule{rule}},
}
s.tc = &testECServiceConn{
mockKeyStorage: mockKeyStorage{privKey: neofscryptotest.ECDSAPrivateKey()},
parentHdr: s.parentHdr,
nodes: make(map[string]*Service),
}
s.nodeSvcs = make([]*Service, len(parts))
for i := range s.nodeSvcs {
s.nodeSvcs[i] = New(&mockNeoFSNet{getNodesForObject: s.getNodesMap, localPubKey: s.nodeLists[0][i].PublicKey()})
s.setPart(i, s.partObjs[i].Payload())
s.tc.nodes[string(s.nodeLists[0][i].Marshal())] = s.nodeSvcs[i]
}
return s
}
// setPart makes node #i serve pld as payload of part #i (nil = part is missing).
func (s *ecAuditScene) setPart(i int, pld []byte) {
m := map[getECPartKey]getECPartValue{}
if pld != nil {
m[getECPartKey{cnr: s.cnr, parent: s.parentHdr.GetID(), pi: iec.PartInfo{Index: i}}] = getECPartValue{
hdr: *s.partObjs[i].CutPayload(), pld: pld, rdr: io.NopCloser(bytes.NewReader(pld)),
}
}
s.nodeSvcs[i].localObjects = &mockLocalObjects{getECPart: m}
}
func (s *ecAuditScene) service() *Service {
svc := New(&mockNeoFSNet{getNodesForObject: s.getNodesMap})
svc.keyStore = s.tc
svc.conns = s.tc
return svc
}
// maliciousLinkerConn answers every part request with a header of a LINK
// object declaring a huge payload.
type maliciousLinkerConn struct {
*testECServiceConn
parent object.Object
size uint64
}
func (x *maliciousLinkerConn) InitGetObjectStream(_ context.Context, _ netmap.NodeInfo, _ ecdsa.PrivateKey,
_ cid.ID, id oid.ID, _, _ bool, _ *object.Range, _ iec.PartInfo) (object.Object, io.ReadCloser, error) {
var hdr object.Object
hdr.SetType(object.TypeLink)
hdr.SetParentID(id)
hdr.SetParent(&x.parent)
hdr.SetPayloadSize(x.size)
return hdr, io.NopCloser(bytes.NewReader(nil)), nil
}
func TestECAuditN2_PeerControlledAllocation(t *testing.T) {
ctx := context.Background()
s := newECAuditScene(t, iec.Rule{DataPartNum: 3, ParityPartNum: 2}, 4096)
svc := s.service()
svc.conns = &maliciousLinkerConn{testECServiceConn: s.tc, parent: s.parentHdr, size: 1 << 62}
t.Run("ranged GET", func(t *testing.T) {
var w mockObjectWriter
var prm Prm
prm.WithAddress(s.parentAddr)
prm.SetCommonParameters(newCommonParameters(false))
prm.SetObjectWriter(&w)
prm.MarkPayloadOnly()
rng := object.NewRange()
rng.SetOffset(1)
rng.SetLength(10)
prm.SetRange(rng)
require.PanicsWithError(t, "runtime error: makeslice: len out of range", func() { _ = svc.Get(ctx, prm) })
})
t.Run("full GET", func(t *testing.T) {
var w mockObjectWriter
var prm Prm
prm.WithAddress(s.parentAddr)
prm.SetCommonParameters(newCommonParameters(false))
prm.SetObjectWriter(&w)
_ = svc.Get(ctx, prm) // panics inside an errgroup goroutine
})
}
Context
Found by an audit of the erasure coding code. The audit was static: code reading plus unit-level probe tests in the packages concerned. No cluster was run, so there is no end-to-end reproduction.
Regression
Not known.
Your Environment
- Version used: 0.58.2 (
1f0d51b5d) - Server setup and configuration: none, unit tests only
- Operating System and version (
uname -a): Darwin 25.6.0 arm64, Go 1.27.3
- 主要言語
- Go
- スター
- 37
- フォーク
- 56
- 平均マージ
- 1日 21時間
- マージ済み PR(30日)
- 46
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nspcc-dev/neofs-node のほかの issue
-
bug hal:proposed neofs-storage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nspcc-dev/neofs-node#4325 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
hal:proposed I4 neofs-storage S3 security U4
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
nspcc-dev/neofs-node#4280 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
nspcc-dev/neofs-node#4339 ·
メンテナーはふだん 1 日以内に返信
-
enhancement I3 neofs-storage performance S3 U3
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
nspcc-dev/neofs-node#4337 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug neofs-storage
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
nspcc-dev/neofs-node#4336 ·
メンテナーはふだん 1 日以内に返信
nspcc-dev/neofs-node の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
OpenSlides/openslides-go#342 ·
メンテナーはふだん 4 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
-
docs: link to the CLA in InditexTech/foss instead of keeping a local CLA.md対応中かも @amagan が今日担当しました。 オープンdocumentation
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
InditexTech/redkey-operator#129 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100