@@ -171,60 +171,60 @@ func disassembleFilter(filter *libseccomp.ScmpFilter) ([]bpf.Instruction, error)
171
171
return program , nil
172
172
}
173
173
174
- type nativeArch uint32
174
+ type linuxAuditArch uint32
175
175
176
- const invalidArch nativeArch = 0
176
+ const invalidArch linuxAuditArch = 0
177
177
178
- func archToNative (arch libseccomp.ScmpArch ) (nativeArch , error ) {
178
+ func scmpArchToAuditArch (arch libseccomp.ScmpArch ) (linuxAuditArch , error ) {
179
179
switch arch {
180
180
case libseccomp .ArchNative :
181
181
// Convert to actual native architecture.
182
182
arch , err := libseccomp .GetNativeArch ()
183
183
if err != nil {
184
184
return invalidArch , fmt .Errorf ("unable to get native arch: %w" , err )
185
185
}
186
- return archToNative (arch )
186
+ return scmpArchToAuditArch (arch )
187
187
case libseccomp .ArchX86 :
188
- return nativeArch (C .C_AUDIT_ARCH_I386 ), nil
188
+ return linuxAuditArch (C .C_AUDIT_ARCH_I386 ), nil
189
189
case libseccomp .ArchAMD64 , libseccomp .ArchX32 :
190
190
// NOTE: x32 is treated like x86_64 except all x32 syscalls have the
191
191
// 30th bit of the syscall number set to indicate that it's not a
192
192
// normal x86_64 syscall.
193
- return nativeArch (C .C_AUDIT_ARCH_X86_64 ), nil
193
+ return linuxAuditArch (C .C_AUDIT_ARCH_X86_64 ), nil
194
194
case libseccomp .ArchARM :
195
- return nativeArch (C .C_AUDIT_ARCH_ARM ), nil
195
+ return linuxAuditArch (C .C_AUDIT_ARCH_ARM ), nil
196
196
case libseccomp .ArchARM64 :
197
- return nativeArch (C .C_AUDIT_ARCH_AARCH64 ), nil
197
+ return linuxAuditArch (C .C_AUDIT_ARCH_AARCH64 ), nil
198
198
case libseccomp .ArchMIPS :
199
- return nativeArch (C .C_AUDIT_ARCH_MIPS ), nil
199
+ return linuxAuditArch (C .C_AUDIT_ARCH_MIPS ), nil
200
200
case libseccomp .ArchMIPS64 :
201
- return nativeArch (C .C_AUDIT_ARCH_MIPS64 ), nil
201
+ return linuxAuditArch (C .C_AUDIT_ARCH_MIPS64 ), nil
202
202
case libseccomp .ArchMIPS64N32 :
203
- return nativeArch (C .C_AUDIT_ARCH_MIPS64N32 ), nil
203
+ return linuxAuditArch (C .C_AUDIT_ARCH_MIPS64N32 ), nil
204
204
case libseccomp .ArchMIPSEL :
205
- return nativeArch (C .C_AUDIT_ARCH_MIPSEL ), nil
205
+ return linuxAuditArch (C .C_AUDIT_ARCH_MIPSEL ), nil
206
206
case libseccomp .ArchMIPSEL64 :
207
- return nativeArch (C .C_AUDIT_ARCH_MIPSEL64 ), nil
207
+ return linuxAuditArch (C .C_AUDIT_ARCH_MIPSEL64 ), nil
208
208
case libseccomp .ArchMIPSEL64N32 :
209
- return nativeArch (C .C_AUDIT_ARCH_MIPSEL64N32 ), nil
209
+ return linuxAuditArch (C .C_AUDIT_ARCH_MIPSEL64N32 ), nil
210
210
case libseccomp .ArchPPC :
211
- return nativeArch (C .C_AUDIT_ARCH_PPC ), nil
211
+ return linuxAuditArch (C .C_AUDIT_ARCH_PPC ), nil
212
212
case libseccomp .ArchPPC64 :
213
- return nativeArch (C .C_AUDIT_ARCH_PPC64 ), nil
213
+ return linuxAuditArch (C .C_AUDIT_ARCH_PPC64 ), nil
214
214
case libseccomp .ArchPPC64LE :
215
- return nativeArch (C .C_AUDIT_ARCH_PPC64LE ), nil
215
+ return linuxAuditArch (C .C_AUDIT_ARCH_PPC64LE ), nil
216
216
case libseccomp .ArchS390 :
217
- return nativeArch (C .C_AUDIT_ARCH_S390 ), nil
217
+ return linuxAuditArch (C .C_AUDIT_ARCH_S390 ), nil
218
218
case libseccomp .ArchS390X :
219
- return nativeArch (C .C_AUDIT_ARCH_S390X ), nil
219
+ return linuxAuditArch (C .C_AUDIT_ARCH_S390X ), nil
220
220
case libseccomp .ArchRISCV64 :
221
- return nativeArch (C .C_AUDIT_ARCH_RISCV64 ), nil
221
+ return linuxAuditArch (C .C_AUDIT_ARCH_RISCV64 ), nil
222
222
default :
223
223
return invalidArch , fmt .Errorf ("unknown architecture: %v" , arch )
224
224
}
225
225
}
226
226
227
- type lastSyscallMap map [nativeArch ]map [libseccomp.ScmpArch ]libseccomp.ScmpSyscall
227
+ type lastSyscallMap map [linuxAuditArch ]map [libseccomp.ScmpArch ]libseccomp.ScmpSyscall
228
228
229
229
// Figure out largest syscall number referenced in the filter for each
230
230
// architecture. We will be generating code based on the native architecture
@@ -241,17 +241,17 @@ func findLastSyscalls(config *configs.Seccomp) (lastSyscallMap, error) {
241
241
}
242
242
243
243
// Figure out native architecture representation of the architecture.
244
- nativeArch , err := archToNative (arch )
244
+ auditArch , err := scmpArchToAuditArch (arch )
245
245
if err != nil {
246
246
return nil , fmt .Errorf ("cannot map architecture %v to AUDIT_ARCH_ constant: %w" , arch , err )
247
247
}
248
248
249
- if _ , ok := lastSyscalls [nativeArch ]; ! ok {
250
- lastSyscalls [nativeArch ] = map [libseccomp.ScmpArch ]libseccomp.ScmpSyscall {}
249
+ if _ , ok := lastSyscalls [auditArch ]; ! ok {
250
+ lastSyscalls [auditArch ] = map [libseccomp.ScmpArch ]libseccomp.ScmpSyscall {}
251
251
}
252
- if _ , ok := lastSyscalls [nativeArch ][arch ]; ok {
252
+ if _ , ok := lastSyscalls [auditArch ][arch ]; ok {
253
253
// Because of ArchNative we may hit the same entry multiple times.
254
- // Just skip it if we've seen this (nativeArch , ScmpArch)
254
+ // Just skip it if we've seen this (linuxAuditArch , ScmpArch)
255
255
// combination before.
256
256
continue
257
257
}
@@ -269,10 +269,11 @@ func findLastSyscalls(config *configs.Seccomp) (lastSyscallMap, error) {
269
269
}
270
270
}
271
271
if largestSyscall != 0 {
272
- lastSyscalls [nativeArch ][arch ] = largestSyscall
272
+ logrus .Debugf ("seccomp: largest syscall number for arch %v is %v" , arch , largestSyscall )
273
+ lastSyscalls [auditArch ][arch ] = largestSyscall
273
274
} else {
274
- logrus .Warnf ("could not find any syscalls for arch %s " , ociArch )
275
- delete (lastSyscalls [nativeArch ], arch )
275
+ logrus .Warnf ("could not find any syscalls for arch %v " , arch )
276
+ delete (lastSyscalls [auditArch ], arch )
276
277
}
277
278
}
278
279
return lastSyscalls , nil
@@ -290,10 +291,10 @@ func findLastSyscalls(config *configs.Seccomp) (lastSyscallMap, error) {
290
291
// close_range(2) which were added out-of-order in the syscall table between
291
292
// kernel releases.
292
293
func generateEnosysStub (lastSyscalls lastSyscallMap ) ([]bpf.Instruction , error ) {
293
- // A jump-table for each nativeArch used to generate the initial
294
+ // A jump-table for each linuxAuditArch used to generate the initial
294
295
// conditional jumps -- measured from the *END* of the program so they
295
296
// remain valid after prepending to the tail.
296
- archJumpTable := map [nativeArch ]uint32 {}
297
+ archJumpTable := map [linuxAuditArch ]uint32 {}
297
298
298
299
// Generate our own -ENOSYS rules for each architecture. They have to be
299
300
// generated in reverse (prepended to the tail of the program) because the
@@ -306,7 +307,7 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
306
307
}
307
308
308
309
// Generate the syscall -ENOSYS rules.
309
- for nativeArch , maxSyscalls := range lastSyscalls {
310
+ for auditArch , maxSyscalls := range lastSyscalls {
310
311
// The number of instructions from the tail of this section which need
311
312
// to be jumped in order to reach the -ENOSYS return. If the section
312
313
// does not jump, it will fall through to the actual filter.
@@ -387,7 +388,7 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
387
388
388
389
// If we're on x86 we need to add a check for x32 and if we're in
389
390
// the wrong mode we jump over the section.
390
- if uint32 (nativeArch ) == uint32 (C .C_AUDIT_ARCH_X86_64 ) {
391
+ if uint32 (auditArch ) == uint32 (C .C_AUDIT_ARCH_X86_64 ) {
391
392
// Generate a prefix to check the mode.
392
393
switch scmpArch {
393
394
case libseccomp .ArchAMD64 :
@@ -416,8 +417,8 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
416
417
section = append (section , sectionTail ... )
417
418
case 2 :
418
419
// x32 and x86_64 are a unique case, we can't handle any others.
419
- if uint32 (nativeArch ) != uint32 (C .C_AUDIT_ARCH_X86_64 ) {
420
- return nil , fmt .Errorf ("unknown architecture overlap on native arch %#x" , nativeArch )
420
+ if uint32 (auditArch ) != uint32 (C .C_AUDIT_ARCH_X86_64 ) {
421
+ return nil , fmt .Errorf ("unknown architecture overlap on native arch %#x" , auditArch )
421
422
}
422
423
423
424
x32sysno , ok := maxSyscalls [libseccomp .ArchX32 ]
@@ -494,7 +495,7 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
494
495
programTail = append (section , programTail ... )
495
496
496
497
// Update jump table.
497
- archJumpTable [nativeArch ] = uint32 (len (programTail ))
498
+ archJumpTable [auditArch ] = uint32 (len (programTail ))
498
499
}
499
500
500
501
// Add a dummy "jump to filter" for any architecture we might miss below.
@@ -514,9 +515,9 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
514
515
// architectures based on how large the jumps are going to be, or
515
516
// re-sort the candidate architectures each time to make sure that we
516
517
// pick the largest jump which is going to be smaller than 255.
517
- for nativeArch := range lastSyscalls {
518
+ for auditArch := range lastSyscalls {
518
519
// We jump forwards but the jump table is calculated from the *END*.
519
- jump := uint32 (len (programTail )) - archJumpTable [nativeArch ]
520
+ jump := uint32 (len (programTail )) - archJumpTable [auditArch ]
520
521
521
522
// Same routine as above -- this is a basic jeq check, complicated
522
523
// slightly if it turns out that we need to do a long jump.
@@ -525,7 +526,7 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
525
526
// jeq [arch],[jump]
526
527
bpf.JumpIf {
527
528
Cond : bpf .JumpEqual ,
528
- Val : uint32 (nativeArch ),
529
+ Val : uint32 (auditArch ),
529
530
SkipTrue : uint8 (jump ),
530
531
},
531
532
}, programTail ... )
@@ -534,7 +535,7 @@ func generateEnosysStub(lastSyscalls lastSyscallMap) ([]bpf.Instruction, error)
534
535
// jne [arch],1
535
536
bpf.JumpIf {
536
537
Cond : bpf .JumpNotEqual ,
537
- Val : uint32 (nativeArch ),
538
+ Val : uint32 (auditArch ),
538
539
SkipTrue : 1 ,
539
540
},
540
541
// ja [jump]
0 commit comments