From 25869dc67afc9dfbbb37a70e882fbcd8200f5068 Mon Sep 17 00:00:00 2001 From: purplerain Date: Tue, 12 Mar 2024 17:08:13 +0000 Subject: [PATCH] sync with OpenBSD -current --- .../usr.sbin/rpki-client/libressl/Makefile | 3 +- regress/usr.sbin/rpki-client/test-http.c | 20 +++++++++ sys/arch/arm64/arm64/db_trace.c | 44 ++++++++++++++----- sys/arch/arm64/arm64/exception.S | 7 ++- sys/dev/mii/ytphy.c | 32 +++++++++++++- usr.sbin/rpki-client/http.c | 7 ++- 6 files changed, 95 insertions(+), 18 deletions(-) diff --git a/regress/usr.sbin/rpki-client/libressl/Makefile b/regress/usr.sbin/rpki-client/libressl/Makefile index bf166cc66..5bb2b337f 100644 --- a/regress/usr.sbin/rpki-client/libressl/Makefile +++ b/regress/usr.sbin/rpki-client/libressl/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.10 2023/06/13 11:41:36 claudio Exp $ +# $OpenBSD: Makefile,v 1.11 2024/03/12 16:03:56 job Exp $ PROGS += test-http @@ -17,6 +17,7 @@ run-regress-test-http: test-http ./test-http https://${SERVER}/HTTP/TE/foo.txt foo.txt ./test-http https://${SERVER}/HTTP/ChunkedScript chunk.out ./test-http https://${SERVER}/HTTP/300/307.html redir.out + -./test-http https://tinyurl.com/bd27n56t /dev/zero sha256 -c ${.CURDIR}/test-http.sum .else # server ${SERVER} not reachable diff --git a/regress/usr.sbin/rpki-client/test-http.c b/regress/usr.sbin/rpki-client/test-http.c index e55037efb..830bb9ca6 100644 --- a/regress/usr.sbin/rpki-client/test-http.c +++ b/regress/usr.sbin/rpki-client/test-http.c @@ -35,6 +35,26 @@ getmonotime(void) return (ts.tv_sec); } +int +valid_origin(const char *uri, const char *proto) +{ + const char *to; + + /* extract end of host from proto URI */ + to = strstr(proto, "://"); + if (to == NULL) + return 0; + to += strlen("://"); + if ((to = strchr(to, '/')) == NULL) + return 0; + + /* compare hosts including the / for the start of the path section */ + if (strncasecmp(uri, proto, to - proto + 1) != 0) + return 0; + + return 1; +} + static void http_request(unsigned int id, const char *uri, const char *last_mod, int fd) { diff --git a/sys/arch/arm64/arm64/db_trace.c b/sys/arch/arm64/arm64/db_trace.c index 0fcfa138f..cd460530a 100644 --- a/sys/arch/arm64/arm64/db_trace.c +++ b/sys/arch/arm64/arm64/db_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_trace.c,v 1.15 2023/06/17 08:13:56 kettenis Exp $ */ +/* $OpenBSD: db_trace.c,v 1.16 2024/03/12 13:32:53 kettenis Exp $ */ /* $NetBSD: db_trace.c,v 1.8 2003/01/17 22:28:48 thorpej Exp $ */ /* @@ -97,8 +97,13 @@ db_stack_trace_print(db_expr_t addr, int have_addr, db_expr_t count, while (count-- && frame != 0) { lastframe = frame; - sym = db_search_symbol(lastlr, DB_STGY_ANY, &offset); - db_symbol_values(sym, &name, NULL); + if (INKERNEL(frame)) { + sym = db_search_symbol(lastlr, DB_STGY_ANY, &offset); + db_symbol_values(sym, &name, NULL); + } else { + sym = NULL; + name = NULL; + } if (name == NULL || strcmp(name, "end") == 0) { (*pr)("%llx at 0x%lx", lastlr, lr - 4); @@ -108,13 +113,6 @@ db_stack_trace_print(db_expr_t addr, int have_addr, db_expr_t count, } (*pr)("\n"); - // can we detect traps ? - db_read_bytes(frame, sizeof(vaddr_t), (char *)&frame); - if (frame == 0) - break; - lastlr = lr; - db_read_bytes(frame + 8, sizeof(vaddr_t), (char *)&lr); - if (name != NULL) { if ((strcmp (name, "handle_el0_irq") == 0) || (strcmp (name, "handle_el1_irq") == 0)) { @@ -125,15 +123,39 @@ db_stack_trace_print(db_expr_t addr, int have_addr, db_expr_t count, (*pr)("--- trap ---\n"); } } + + lastframe = frame; + db_read_bytes(frame, sizeof(vaddr_t), (char *)&frame); + + if (frame == 0) { + /* end of chain */ + break; + } + if (INKERNEL(frame)) { + /* staying in kernel */ if (frame <= lastframe) { (*pr)("Bad frame pointer: 0x%lx\n", frame); break; } + } else if (INKERNEL(lastframe)) { + /* switch from user to kernel */ + if (kernel_only) { + (*pr)("end of kernel\n"); + break; /* kernel stack only */ + } } else { - if (kernel_only) + /* in user */ + if (frame <= lastframe) { + (*pr)("Bad user frame pointer: 0x%lx\n", + frame); break; + } } + + lastlr = lr; + db_read_bytes(frame + 8, sizeof(vaddr_t), (char *)&lr); + --count; } } diff --git a/sys/arch/arm64/arm64/exception.S b/sys/arch/arm64/arm64/exception.S index 1a1ff5fb6..101de9ef8 100644 --- a/sys/arch/arm64/arm64/exception.S +++ b/sys/arch/arm64/arm64/exception.S @@ -1,4 +1,4 @@ -/* $OpenBSD: exception.S,v 1.16 2023/12/26 09:19:15 kettenis Exp $ */ +/* $OpenBSD: exception.S,v 1.17 2024/03/12 13:32:53 kettenis Exp $ */ /*- * Copyright (c) 2014 Andrew Turner * All rights reserved. @@ -38,7 +38,6 @@ sub sp, sp, #128 .endif sub sp, sp, #(TF_SIZE + 16) - stp x29, x30, [sp, #(TF_SIZE)] stp x28, x29, [sp, #(TF_X + 28 * 8)] stp x26, x27, [sp, #(TF_X + 26 * 8)] stp x24, x25, [sp, #(TF_X + 24 * 8)] @@ -59,11 +58,11 @@ .if \el == 0 mrs x18, sp_el0 .endif - mov fp, x18 stp x10, x11, [sp, #(TF_ELR)] stp x18, lr, [sp, #(TF_SP)] + stp fp, x10, [sp, #(TF_SIZE)] mrs x18, tpidr_el1 - add x29, sp, #(TF_SIZE) + add fp, sp, #(TF_SIZE) .endm .macro restore_registers el diff --git a/sys/dev/mii/ytphy.c b/sys/dev/mii/ytphy.c index dcac444cd..b08ea4085 100644 --- a/sys/dev/mii/ytphy.c +++ b/sys/dev/mii/ytphy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ytphy.c,v 1.5 2024/02/08 13:00:21 jsg Exp $ */ +/* $OpenBSD: ytphy.c,v 1.6 2024/03/12 16:26:46 kettenis Exp $ */ /* * Copyright (c) 2001 Theo de Raadt * Copyright (c) 2023 Mark Kettenis @@ -73,6 +73,12 @@ #define YT8531_RGMII_RXD_DS_MASK ((0x1 << 12) | (0x3 << 4)) #define YT8531_RGMII_RXD_DS_LOW(x) (((x) & 0x3) << 4) #define YT8531_RGMII_RXD_DS_HIGH(x) (((x) >> 2) << 12) +#define YT8521_EXT_SYNCE_CFG 0xa012 +#define YT8531_EN_SYNC_E (1 << 6) +#define YT8531_CLK_FRE_SEL_125M (1 << 4) +#define YT8531_CLK_SRC_SEL_MASK (0x7 << 1) +#define YT8531_CLK_SRC_SEL_PLL_125M (0x0 << 1) +#define YT8531_CLK_SRC_SEL_REF_25M (0x4 << 1) int ytphy_match(struct device *, void *, void *); void ytphy_attach(struct device *, struct device *, void *); @@ -428,6 +434,7 @@ ytphy_yt8531_init(struct mii_softc *sc) { uint32_t rx_clk_drv = 0; uint32_t rx_data_drv = 0; + uint32_t clk_out_freq = 0; uint16_t addr, data; uint16_t volt; @@ -439,6 +446,8 @@ ytphy_yt8531_init(struct mii_softc *sc) "motorcomm,rx-clk-drv-microamp", 0); rx_data_drv = OF_getpropint(sc->mii_pdata->mii_node, "motorcomm,rx-data-drv-microamp", 0); + clk_out_freq = OF_getpropint(sc->mii_pdata->mii_node, + "motorcomm,clk-out-frequency-hz", 0); } #endif @@ -466,6 +475,27 @@ ytphy_yt8531_init(struct mii_softc *sc) data |= YT8531_RGMII_RXD_DS_HIGH(rx_data_drv); PHY_WRITE(sc, YT8511_REG_DATA, data); + PHY_WRITE(sc, YT8511_REG_ADDR, YT8521_EXT_SYNCE_CFG); + data = PHY_READ(sc, YT8511_REG_DATA); + switch (clk_out_freq) { + case 125000000: + data |= YT8531_EN_SYNC_E; + data |= YT8531_CLK_FRE_SEL_125M; + data &= ~YT8531_CLK_SRC_SEL_MASK; + data |= YT8531_CLK_SRC_SEL_PLL_125M; + break; + case 25000000: + data |= YT8531_EN_SYNC_E; + data &= ~YT8531_CLK_FRE_SEL_125M; + data &= ~YT8531_CLK_SRC_SEL_MASK; + data |= YT8531_CLK_SRC_SEL_REF_25M; + break; + default: + data &= ~YT8531_EN_SYNC_E; + break; + } + PHY_WRITE(sc, YT8511_REG_DATA, data); + /* Restore address register. */ PHY_WRITE(sc, YT8511_REG_ADDR, addr); } diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index 282487aa1..2d76f67d9 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.80 2024/01/30 11:15:05 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.81 2024/03/12 16:02:30 job Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -1417,6 +1417,11 @@ http_parse_header(struct http_connection *conn, char *buf) if (loctail != NULL) *loctail = '\0'; conn->redir_uri = redirurl; + if (!valid_origin(redirurl, conn->req->uri)) { + warnx("%s: cross origin redirect to %s", conn->req->uri, + http_info(redirurl)); + return -1; + } } else if (strncasecmp(cp, TRANSFER_ENCODING, sizeof(TRANSFER_ENCODING) - 1) == 0) { cp += sizeof(TRANSFER_ENCODING) - 1;