Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WAF to 1.15.0 #39

Merged
merged 32 commits into from
Nov 7, 2023
Merged

Update WAF to 1.15.0 #39

merged 32 commits into from
Nov 7, 2023

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Nov 3, 2023

Also re-wrote the update.sh to be in go, for improved expressiveness. This includes dropping the strip pass as the musl linux images are already stripped, and this was just a waste of time.

@RomainMuller RomainMuller changed the title Update WAF to 1.14.0 Update WAF to 1.15.0 Nov 3, 2023
@RomainMuller RomainMuller marked this pull request as draft November 3, 2023 14:59
Base automatically changed from 2.0 to main November 3, 2023 15:05
embed_darwin_arm64.go Outdated Show resolved Hide resolved
Copy link
Contributor

@eliottness eliottness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First look at it, a couple of nits:

  • Can you add tests that use permanent and ephemeral addresses at the same time?
  • Can you put the right permissions back on the embedded files ? (755 instead of 644)
  • The embedded libddwaf on OSX where named with _ before for a very specific reason but I can't reproduce it since I don't have a Mac anymore, let's keep it in the back of our mind for now.
  • As you can see in the run() function, we keep track of the ddwaf_object parameter in the context struct because it is required for them to live all the way to the end of the context. My guess is that this is not the case for ephemeral addresses. Can you take a look at this with @Anilm3 ?

context.go Show resolved Hide resolved
context.go Show resolved Hide resolved
context.go Outdated Show resolved Hide resolved
context.go Outdated Show resolved Hide resolved
context.go Outdated Show resolved Hide resolved
@Anilm3
Copy link

Anilm3 commented Nov 3, 2023

  • As you can see in the run() function, we keep track of the ddwaf_object parameter in the context struct because it is required for them to live all the way to the end of the context. My guess is that this is not the case for ephemeral addresses. Can you take a look at this with @Anilm3 ?

Ephemeral addresses are freed at the end of ddwaf_run.

@RomainMuller
Copy link
Contributor Author

  • Can you put the right permissions back on the embedded files ? (755 instead of 644)

Why'd they need to be executable? They're embedded as a byte slice in another file, and the file permissions won't be persisted when doing that anyway?

# Conflicts:
#	context.go
#	decoder.go
#	include/ddwaf.h
#	lib/darwin-amd64/_libddwaf.dylib
#	lib/darwin-arm64/_libddwaf.dylib
#	lib/linux-amd64/libddwaf.so
#	lib/linux-arm64/libddwaf.so
#	waf.go
#	waf_dl.go
#	waf_dl_unsupported.go
#	waf_test.go
@RomainMuller RomainMuller marked this pull request as ready for review November 6, 2023 10:19
@eliottness
Copy link
Contributor

  • Can you put the right permissions back on the embedded files ? (755 instead of 644)

Why'd they need to be executable? They're embedded as a byte slice in another file, and the file permissions won't be persisted when doing that anyway?

@RomainMuller This is very useful to link the library directly when debugging with a small C script. That's usually why we need to put it in 755. But more than that, it's to avoid dealing with the wierdest errors coming from the linker trying to access the library (./a.out: permission denied or ./a.out: no such file or directly)

@RomainMuller
Copy link
Contributor Author

@RomainMuller This is very useful to link the library directly when debugging with a small C script. That's usually why we need to put it in 755.

That I can understand... even though this sounds like a micro-improvement.

But more than that, it's to avoid dealing with the wierdest errors coming from the linker trying to access the library (./a.out: permission denied or ./a.out: no such file or directly)

That is only relevant when trying to directly link to those files locally, and won't change a thing with the embed (the permissions of the file we dump in a temporary location is what matters here).

Copy link
Contributor

@eliottness eliottness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Thanks for all of this already

_tools/libddwaf-updater/update.go Outdated Show resolved Hide resolved
_tools/libddwaf-updater/update.go Outdated Show resolved Hide resolved
_tools/libddwaf-updater/update.go Show resolved Hide resolved
_tools/libddwaf-updater/update.go Outdated Show resolved Hide resolved
encoder_test.go Outdated Show resolved Hide resolved
internal/vendor/README.md Outdated Show resolved Hide resolved
waf_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@eliottness eliottness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥳

Copy link
Contributor

@Hellzy Hellzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Typo nit

_tools/libddwaf-updater/update.go Outdated Show resolved Hide resolved
_tools/libddwaf-updater/update.go Outdated Show resolved Hide resolved
@@ -85,12 +113,12 @@ func (context *Context) Run(addressesToData map[string]any, timeout time.Duratio

// Save the Go pointer references to addressesToData that were referenced by the encoder
// into C ddwaf_objects. libddwaf's API requires to keep this data for the lifetime of the ddwaf_context.
defer context.cgoRefs.append(encoder.cgoRefs)
defer context.cgoRefs.append(persistentEncoder.cgoRefs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What allows us not to append ephemeralData.cgoRefs?
IIUC, we can avoid it because the Go reference is kept by this function call.
But if that's the case, I would try to ensure it even more explicitly to avoid potential compiler optimizations somehow removing the reference. WDYT?

Copy link
Collaborator

@Julio-Guerra Julio-Guerra Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any test on ephemeral addresses and that might be why this problem wasn't caught.
Can you please add this new type of entry in the TestConcurrency tests? This is the test suite that allowed us to find all the issues we had with the purego port.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are definitely tests on ephemeral addresses. Not in the concurrent suite (but I also am not sure how this would uncover anything the other test hasn't).

Copy link
Contributor

@Hellzy Hellzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you used a bunch of interface{} type in the tests 😛
Not a blocker but consistency would have us switch to any when we can as you pointed out in other changes.

@RomainMuller
Copy link
Contributor Author

I noticed you used a bunch of interface{} type in the tests 😛 Not a blocker but consistency would have us switch to any when we can as you pointed out in other changes.

Yeah - these were copied from surrounding style... I did not want to do a global replace as it would have further inflated the diff size...

@RomainMuller RomainMuller merged commit 643bed9 into main Nov 7, 2023
61 checks passed
@RomainMuller RomainMuller deleted the rmuller/waf-1.15.0 branch November 7, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants