ssh/agent: prevent panic on malformed constraint
An attacker could supply a malformed Constraint that would trigger a panic in a serving agent, effectively causing denial of service. Thank you to Jakub Ciolek for reporting this issue. Fixes CVE-2025-47914 Fixes golang/go#76364 Change-Id: I195bbc68b1560d4f04897722a6a653a7cbf086eb Reviewed-on: https://go-review.googlesource.com/c/crypto/+/721960 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
@@ -203,6 +203,9 @@ func parseConstraints(constraints []byte) (lifetimeSecs uint32, confirmBeforeUse
|
|||||||
for len(constraints) != 0 {
|
for len(constraints) != 0 {
|
||||||
switch constraints[0] {
|
switch constraints[0] {
|
||||||
case agentConstrainLifetime:
|
case agentConstrainLifetime:
|
||||||
|
if len(constraints) < 5 {
|
||||||
|
return 0, false, nil, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
lifetimeSecs = binary.BigEndian.Uint32(constraints[1:5])
|
lifetimeSecs = binary.BigEndian.Uint32(constraints[1:5])
|
||||||
constraints = constraints[5:]
|
constraints = constraints[5:]
|
||||||
case agentConstrainConfirm:
|
case agentConstrainConfirm:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"crypto"
|
"crypto"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
pseudorand "math/rand"
|
pseudorand "math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -258,6 +259,12 @@ func TestParseConstraints(t *testing.T) {
|
|||||||
t.Errorf("got extension %v, want %v", extensions, expect)
|
t.Errorf("got extension %v, want %v", extensions, expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test Malformed Constraint
|
||||||
|
_, _, _, err = parseConstraints([]byte{1})
|
||||||
|
if err != io.ErrUnexpectedEOF {
|
||||||
|
t.Errorf("got %v, want %v", err, io.ErrUnexpectedEOF)
|
||||||
|
}
|
||||||
|
|
||||||
// Test Unknown Constraint
|
// Test Unknown Constraint
|
||||||
_, _, _, err = parseConstraints([]byte{128})
|
_, _, _, err = parseConstraints([]byte{128})
|
||||||
if err == nil || !strings.Contains(err.Error(), "unknown constraint") {
|
if err == nil || !strings.Contains(err.Error(), "unknown constraint") {
|
||||||
|
|||||||
Reference in New Issue
Block a user