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

gcoap: fix underflow when correcting ETag from cache #19968

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Oct 10, 2023

Contribution description

Fixes an underflow error when getting a new ETag from cache, by returning early.

Testing procedure

I repeated the testing procedures from #17801 (comment) (attention, the expected input for examples/gcoap changed slightly in the last year and a half)

diff --git a/aiocoap/cli/fileserver.py b/aiocoap/cli/fileserver.py
index 6af2b84..f5a9e71 100644
--- a/aiocoap/cli/fileserver.py
+++ b/aiocoap/cli/fileserver.py
@@ -154,6 +154,7 @@ class FileServer(Resource, aiocoap.interfaces.ObservableResource):
             elif S_ISREG(st.st_mode):
                 response = await self.render_get_file(request, path)
 
+        response.opt.max_age = 10
         response.opt.etag = etag
         return response
 

)

$ sudo ./dist/tool/tapsetup/tapsetup
$ PORT=tap1 USEMODULE="gcoap_forward_proxy nanocoap_cache" make -C examples/gcoap -j flash term
...
> ifconfig
ifconfig
Iface  6  HWaddr: DA:27:1D:A8:64:24 
          L2-PDU:1500  MTU:1500  HL:64  Source address length: 6
          Link type: wired
          inet6 addr: fe80::d827:1dff:fea8:6424  scope: link  VAL
          inet6 group: ff02::1
          inet6 group: ff02::1:ffa8:6424

> 
[second terminal in aiocoap repo]
$ ip addr show dev tapbr0 scope link
5: tapbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether de:1a:a8:09:45:b3 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::dc1a:a8ff:fe09:45b3/64 scope link proto kernel_ll 
       valid_lft forever preferred_lft forever
$ mkdir -p test
$ echo "foobar" > test/a.txt
$ ./aiocoap-fileserver --bind "[$(ip addr show dev tapbr0 scope link | grep -o 'inet6 [0-9a-f:]\+' | sed 's/inet6 //')%tapbr0]" test/
...
[third terminal]
$ make -C examples/gcoap term
All up, running the shell now
> coap proxy set [fe80::d827:1dff:fea8:6424]:5683
coap proxy set [fe80::d827:1dff:fea8:6424]:5683
> coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
gcoap_cli: sending msg ID 17604, 63 bytes
> --- blockwise start ---
gcoap: response Success, code 2.05, 7 bytes
foobar

--- blockwise complete ---
coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
gcoap_cli: sending msg ID 17605, 63 bytes
--- blockwise start ---
gcoap: response Success, code 2.05, 7 bytes
foobar

--- blockwise complete ---

[wait >10 sec]

> coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
gcoap_cli: sending msg ID 17606, 63 bytes
> --- blockwise start ---
gcoap: response Success, code 2.05, 7 bytes
foobar

--- blockwise complete ---
coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
coap get [fe80::dc1a:a8ff:fe09:45b3]:5683 /a.txt
gcoap_cli: sending msg ID 17607, 63 bytes
--- blockwise start ---
gcoap: response Success, code 2.05, 7 bytes
foobar

--- blockwise complete ---
> ^C
native: exiting

Sniffing on tapbr0 should show something like.

image

Issues/PRs references

Reported off-band.

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: CoAP Area: Constrained Application Protocol implementations labels Oct 10, 2023
@miri64 miri64 requested a review from MrKevinWeiss October 10, 2023 12:55
@github-actions github-actions bot added the Area: sys Area: System label Oct 10, 2023
@riot-ci
Copy link

riot-ci commented Oct 10, 2023

Murdock results

✔️ PASSED

8d1cb1b gcoap: fix underflow when correcting ETag from cache

Success Failures Total Runtime
7937 0 7937 14m:31s

Artifacts

@benpicco benpicco requested a review from chrysn October 10, 2023 13:52
Copy link
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

I find it weird that we allow responses with invalid ETag values into our caches in the first place, or that opt_get_opaque can even return values outside the buffer, but that'd probably be out of scope for the bug fix here.

Looks good to me.

Note for other reviewers: The example given in the report is not showing errant behavior, it merely demonstrates that things work fine before and after when given valid inputs.

DEBUG("gcoap: invalid calculated padding length (%lu) for ETag injection "
"during cache lookup.\n", (long unsigned)rem_len);
/* something fishy happened in the request. Better don't return cache entry */
*cache_hit = false;
Copy link
Member

Choose a reason for hiding this comment

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

That's already false from an earlier check, but it doesn't hurt to be explicit either (the compiler will remove it anyway).

@chrysn
Copy link
Member

chrysn commented Oct 13, 2023

bors merge

bors bot added a commit that referenced this pull request Oct 13, 2023
19968: gcoap: fix underflow when correcting ETag from cache r=chrysn a=miri64



Co-authored-by: Martine Lenders <m.lenders@fu-berlin.de>
@bors
Copy link
Contributor

bors bot commented Oct 13, 2023

Build failed:

  • static-tests

@miri64
Copy link
Member Author

miri64 commented Oct 13, 2023

Build failed:

* static-tests

Seems completely unrelated. :-(

@MrKevinWeiss MrKevinWeiss added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Oct 16, 2023
@miri64
Copy link
Member Author

miri64 commented Oct 17, 2023

bors merge

bors bot added a commit that referenced this pull request Oct 17, 2023
19968: gcoap: fix underflow when correcting ETag from cache r=miri64 a=miri64



Co-authored-by: Martine Lenders <m.lenders@fu-berlin.de>
@bors
Copy link
Contributor

bors bot commented Oct 17, 2023

Build failed:

@miri64
Copy link
Member Author

miri64 commented Oct 17, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Oct 17, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit b6772c8 into RIOT-OS:master Oct 17, 2023
29 checks passed
@miri64 miri64 deleted the gcoap/fix/underflow branch October 18, 2023 06:47
bors bot added a commit that referenced this pull request Oct 18, 2023
19987: gcoap: fix underflow when correcting ETag from cache [backport 2023.10] r=miri64 a=MrKevinWeiss

# Backport of #19968



Co-authored-by: Martine Lenders <m.lenders@fu-berlin.de>
bors bot added a commit that referenced this pull request Oct 19, 2023
19984: dist/testbed-support: Add openmote board [backport 2023.10] r=MrKevinWeiss a=miri64

# Backport of #19979

### Contribution description

As part of fixing the automated release specs test we will need support for another `cc2538` based board.  I was able to get the tests passing with adaption here and to the release specs.

### Testing procedure

### Issues/PRs references


19987: gcoap: fix underflow when correcting ETag from cache [backport 2023.10] r=miri64 a=MrKevinWeiss

# Backport of #19968



Co-authored-by: MrKevinWeiss <weiss.kevin604@gmail.com>
Co-authored-by: Martine Lenders <m.lenders@fu-berlin.de>
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.01 milestone Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants