From 87edded1683044e3d2775bb27ee8e9db185147d3 Mon Sep 17 00:00:00 2001 From: tobhe Date: Sun, 24 Oct 2021 14:50:42 +0000 Subject: [PATCH] Remove crp_etype and return errors directly from crypto_invoke() ok patrick@ --- sys/crypto/crypto.c | 12 +++--- sys/crypto/cryptodev.h | 14 +------ sys/dev/softraid_crypto.c | 81 +++++++++++++++------------------------ sys/dev/softraid_raid1c.c | 49 +++++++++-------------- sys/netinet/ip_ah.c | 20 ++++------ sys/netinet/ip_esp.c | 20 ++++------ sys/netinet/ip_ipcomp.c | 21 ++++------ 7 files changed, 80 insertions(+), 137 deletions(-) diff --git a/sys/crypto/crypto.c b/sys/crypto/crypto.c index a51edbbbada..ea9f36060b8 100644 --- a/sys/crypto/crypto.c +++ b/sys/crypto/crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crypto.c,v 1.91 2021/10/24 10:26:22 patrick Exp $ */ +/* $OpenBSD: crypto.c,v 1.92 2021/10/24 14:50:42 tobhe Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) * @@ -379,7 +379,7 @@ crypto_unregister(u_int32_t driverid, int alg) /* * Dispatch a crypto request to the appropriate crypto devices. */ -void +int crypto_invoke(struct cryptop *crp) { u_int64_t nid; @@ -394,7 +394,7 @@ crypto_invoke(struct cryptop *crp) s = splvm(); if (crp->crp_ndesc < 1 || crypto_drivers == NULL) { - crp->crp_etype = EINVAL; + error = EINVAL; goto done; } @@ -414,7 +414,6 @@ crypto_invoke(struct cryptop *crp) crypto_drivers[hid].cc_bytes += crp->crp_ilen; error = crypto_drivers[hid].cc_process(crp); - crp->crp_etype = error; if (error == ERESTART) { /* Unregister driver and migrate session. */ crypto_unregister(hid, CRYPTO_ALGORITHM_MAX + 1); @@ -422,7 +421,7 @@ crypto_invoke(struct cryptop *crp) } splx(s); - return; + return error; migrate: /* Migrate session. */ @@ -433,9 +432,10 @@ crypto_invoke(struct cryptop *crp) if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI), 0) == 0) crp->crp_sid = nid; - crp->crp_etype = EAGAIN; + error = EAGAIN; done: splx(s); + return error; } /* diff --git a/sys/crypto/cryptodev.h b/sys/crypto/cryptodev.h index 4af72c7a9a5..9f353aa86b6 100644 --- a/sys/crypto/cryptodev.h +++ b/sys/crypto/cryptodev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptodev.h,v 1.80 2021/10/23 15:42:35 tobhe Exp $ */ +/* $OpenBSD: cryptodev.h,v 1.81 2021/10/24 14:50:42 tobhe Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -154,16 +154,6 @@ struct cryptop { int crp_olen; /* Result total length */ int crp_alloctype; /* Type of buf to allocate if needed */ - int crp_etype; /* - * Error type (zero means no error). - * All error codes except EAGAIN - * indicate possible data corruption (as in, - * the data have been touched). On all - * errors, the crp_sid may have changed - * (reset to a new one), so the caller - * should always check and use the new - * value on future requests. - */ int crp_flags; #define CRYPTO_F_IMBUF 0x0001 /* Input/output are mbuf chains, otherwise contig */ @@ -215,7 +205,7 @@ int crypto_register(u_int32_t, int *, int (*)(struct cryptop *)); int crypto_unregister(u_int32_t, int); int32_t crypto_get_driverid(u_int8_t); -void crypto_invoke(struct cryptop *); +int crypto_invoke(struct cryptop *); void cuio_copydata(struct uio *, int, int, caddr_t); void cuio_copyback(struct uio *, int, int, const void *); diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 376deb19b01..fbe8358e5dd 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.144 2021/10/23 15:42:35 tobhe Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.145 2021/10/24 14:50:42 tobhe Exp $ */ /* * Copyright (c) 2007 Marco Peereboom * Copyright (c) 2008 Hans-Joerg Hoexer @@ -87,13 +87,11 @@ int sr_crypto_meta_opt_handler_internal(struct sr_discipline *, struct sr_crypto *, struct sr_meta_opt_hdr *); int sr_crypto_meta_opt_handler(struct sr_discipline *, struct sr_meta_opt_hdr *); -void sr_crypto_write(struct sr_crypto_wu *); int sr_crypto_rw(struct sr_workunit *); int sr_crypto_dev_rw(struct sr_workunit *, struct sr_crypto_wu *); void sr_crypto_done_internal(struct sr_workunit *, struct sr_crypto *); void sr_crypto_done(struct sr_workunit *); -void sr_crypto_read(struct sr_crypto_wu *); void sr_crypto_calculate_check_hmac_sha1(u_int8_t *, int, u_int8_t *, int, u_char *); void sr_crypto_hotplug(struct sr_discipline *, struct disk *, int); @@ -1156,7 +1154,8 @@ sr_crypto_rw(struct sr_workunit *wu) struct sr_crypto_wu *crwu; struct sr_crypto *mdd_crypto; daddr_t blkno; - int rv; + int rv, err; + int s; DNPRINTF(SR_D_DIS, "%s: sr_crypto_rw wu %p\n", DEVNAME(wu->swu_dis->sd_sc), wu); @@ -1167,33 +1166,25 @@ sr_crypto_rw(struct sr_workunit *wu) if (wu->swu_xs->flags & SCSI_DATA_OUT) { mdd_crypto = &wu->swu_dis->mds.mdd_crypto; crwu = sr_crypto_prepare(wu, mdd_crypto, 1); - crypto_invoke(crwu->cr_crp); - sr_crypto_write(crwu); - rv = crwu->cr_crp->crp_etype; - } else - rv = sr_crypto_dev_rw(wu, NULL); + rv = crypto_invoke(crwu->cr_crp); - return (rv); -} - -void -sr_crypto_write(struct sr_crypto_wu *crwu) -{ - struct sr_workunit *wu = &crwu->cr_wu; - int s; + DNPRINTF(SR_D_INTR, "%s: sr_crypto_rw: wu %p xs: %p\n", + DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs); - DNPRINTF(SR_D_INTR, "%s: sr_crypto_write: wu %p xs: %p\n", - DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs); + if (rv) { + /* fail io */ + wu->swu_xs->error = XS_DRIVER_STUFFUP; + s = splbio(); + sr_scsi_done(wu->swu_dis, wu->swu_xs); + splx(s); + } - if (crwu->cr_crp->crp_etype) { - /* fail io */ - wu->swu_xs->error = XS_DRIVER_STUFFUP; - s = splbio(); - sr_scsi_done(wu->swu_dis, wu->swu_xs); - splx(s); - } + if ((err = sr_crypto_dev_rw(wu, crwu)) != 0) + return err; + } else + rv = sr_crypto_dev_rw(wu, NULL); - sr_crypto_dev_rw(wu, crwu); + return (rv); } int @@ -1225,10 +1216,7 @@ sr_crypto_dev_rw(struct sr_workunit *wu, struct sr_crypto_wu *crwu) return (0); bad: - /* wu is unwound by sr_wu_put */ - if (crwu) - crwu->cr_crp->crp_etype = EINVAL; - return (1); + return (EINVAL); } void @@ -1236,6 +1224,7 @@ sr_crypto_done_internal(struct sr_workunit *wu, struct sr_crypto *mdd_crypto) { struct scsi_xfer *xs = wu->swu_xs; struct sr_crypto_wu *crwu; + int rv; int s; if (ISSET(wu->swu_flags, SR_WUF_REBUILD)) /* RAID 1C */ @@ -1246,8 +1235,17 @@ sr_crypto_done_internal(struct sr_workunit *wu, struct sr_crypto *mdd_crypto) crwu = sr_crypto_prepare(wu, mdd_crypto, 0); DNPRINTF(SR_D_INTR, "%s: sr_crypto_done: crypto_invoke %p\n", DEVNAME(wu->swu_dis->sd_sc), crwu->cr_crp); - crypto_invoke(crwu->cr_crp); - sr_crypto_read(crwu); + rv = crypto_invoke(crwu->cr_crp); + + DNPRINTF(SR_D_INTR, "%s: sr_crypto_done: wu %p xs: %p\n", + DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs); + + if (rv) + wu->swu_xs->error = XS_DRIVER_STUFFUP; + + s = splbio(); + sr_scsi_done(wu->swu_dis, wu->swu_xs); + splx(s); return; } @@ -1263,23 +1261,6 @@ sr_crypto_done(struct sr_workunit *wu) sr_crypto_done_internal(wu, mdd_crypto); } -void -sr_crypto_read(struct sr_crypto_wu *crwu) -{ - struct sr_workunit *wu = &crwu->cr_wu; - int s; - - DNPRINTF(SR_D_INTR, "%s: sr_crypto_read: wu %p xs: %p\n", - DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs); - - if (crwu->cr_crp->crp_etype) - wu->swu_xs->error = XS_DRIVER_STUFFUP; - - s = splbio(); - sr_scsi_done(wu->swu_dis, wu->swu_xs); - splx(s); -} - void sr_crypto_hotplug(struct sr_discipline *sd, struct disk *diskp, int action) { diff --git a/sys/dev/softraid_raid1c.c b/sys/dev/softraid_raid1c.c index d428709aedb..47ab5e22716 100644 --- a/sys/dev/softraid_raid1c.c +++ b/sys/dev/softraid_raid1c.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid1c.c,v 1.5 2021/10/23 15:42:35 tobhe Exp $ */ +/* $OpenBSD: softraid_raid1c.c,v 1.6 2021/10/24 14:50:42 tobhe Exp $ */ /* * Copyright (c) 2007 Marco Peereboom * Copyright (c) 2008 Hans-Joerg Hoexer @@ -58,7 +58,6 @@ void sr_raid1c_free_resources(struct sr_discipline *sd); int sr_raid1c_ioctl(struct sr_discipline *sd, struct bioc_discipline *bd); int sr_raid1c_meta_opt_handler(struct sr_discipline *, struct sr_meta_opt_hdr *); -void sr_raid1c_write(struct sr_crypto_wu *); int sr_raid1c_rw(struct sr_workunit *); int sr_raid1c_dev_rw(struct sr_workunit *, struct sr_crypto_wu *); void sr_raid1c_done(struct sr_workunit *wu); @@ -305,30 +304,7 @@ ragain: return (0); bad: - /* wu is unwound by sr_wu_put */ - if (crwu) - crwu->cr_crp->crp_etype = EINVAL; - return (1); -} - -void -sr_raid1c_write(struct sr_crypto_wu *crwu) -{ - struct sr_workunit *wu = &crwu->cr_wu; - int s; - - DNPRINTF(SR_D_INTR, "%s: sr_raid1c_write: wu %p xs: %p\n", - DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs); - - if (crwu->cr_crp->crp_etype) { - /* fail io */ - wu->swu_xs->error = XS_DRIVER_STUFFUP; - s = splbio(); - sr_scsi_done(wu->swu_dis, wu->swu_xs); - splx(s); - } - - sr_raid1c_dev_rw(wu, crwu); + return (EINVAL); } int @@ -345,7 +321,8 @@ sr_raid1c_rw(struct sr_workunit *wu) struct sr_crypto_wu *crwu; struct sr_raid1c *mdd_raid1c; daddr_t blkno; - int rv; + int rv, err; + int s; DNPRINTF(SR_D_DIS, "%s: sr_raid1c_rw wu %p\n", DEVNAME(wu->swu_dis->sd_sc), wu); @@ -357,9 +334,21 @@ sr_raid1c_rw(struct sr_workunit *wu) !ISSET(wu->swu_flags, SR_WUF_REBUILD)) { mdd_raid1c = &wu->swu_dis->mds.mdd_raid1c; crwu = sr_crypto_prepare(wu, &mdd_raid1c->sr1c_crypto, 1); - crypto_invoke(crwu->cr_crp); - sr_raid1c_write(crwu); - rv = crwu->cr_crp->crp_etype; + rv = crypto_invoke(crwu->cr_crp); + + DNPRINTF(SR_D_INTR, "%s: sr_raid1c_rw: wu %p xs: %p\n", + DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs); + + if (rv) { + /* fail io */ + wu->swu_xs->error = XS_DRIVER_STUFFUP; + s = splbio(); + sr_scsi_done(wu->swu_dis, wu->swu_xs); + splx(s); + } + + if ((err = sr_raid1c_dev_rw(wu, crwu)) != 0) + return (err); } else rv = sr_raid1c_dev_rw(wu, NULL); diff --git a/sys/netinet/ip_ah.c b/sys/netinet/ip_ah.c index 3d2f28e77e5..23ea3ffb12a 100644 --- a/sys/netinet/ip_ah.c +++ b/sys/netinet/ip_ah.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ah.c,v 1.161 2021/10/24 14:24:29 bluhm Exp $ */ +/* $OpenBSD: ip_ah.c,v 1.162 2021/10/24 14:50:42 tobhe Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -700,18 +700,15 @@ ah_input(struct mbuf **mp, struct tdb *tdb, int skip, int protoff) tc->tc_rpl = tdb->tdb_rpl; KERNEL_LOCK(); - crypto_invoke(crp); - while (crp->crp_etype == EAGAIN) { + while ((error = crypto_invoke(crp)) == EAGAIN) { /* Reset the session ID */ if (tdb->tdb_cryptoid != 0) tdb->tdb_cryptoid = crp->crp_sid; - crypto_invoke(crp); } KERNEL_UNLOCK(); - if (crp->crp_etype) { - DPRINTF("crypto error %d", crp->crp_etype); + if (error) { + DPRINTF("crypto error %d", error); ipsecstat_inc(ipsec_noxform); - error = crp->crp_etype; goto drop; } @@ -1165,18 +1162,15 @@ ah_output(struct mbuf *m, struct tdb *tdb, int skip, int protoff) memcpy(&tc->tc_dst, &tdb->tdb_dst, sizeof(union sockaddr_union)); KERNEL_LOCK(); - crypto_invoke(crp); - while (crp->crp_etype == EAGAIN) { + while ((error = crypto_invoke(crp)) == EAGAIN) { /* Reset the session ID */ if (tdb->tdb_cryptoid != 0) tdb->tdb_cryptoid = crp->crp_sid; - crypto_invoke(crp); } KERNEL_UNLOCK(); - if (crp->crp_etype) { - DPRINTF("crypto error %d", crp->crp_etype); + if (error) { + DPRINTF("crypto error %d", error); ipsecstat_inc(ipsec_noxform); - error = crp->crp_etype; goto drop; } diff --git a/sys/netinet/ip_esp.c b/sys/netinet/ip_esp.c index d84ccbbc628..afdf5608993 100644 --- a/sys/netinet/ip_esp.c +++ b/sys/netinet/ip_esp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_esp.c,v 1.180 2021/10/24 14:24:29 bluhm Exp $ */ +/* $OpenBSD: ip_esp.c,v 1.181 2021/10/24 14:50:42 tobhe Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -526,18 +526,15 @@ esp_input(struct mbuf **mp, struct tdb *tdb, int skip, int protoff) } KERNEL_LOCK(); - crypto_invoke(crp); - while (crp->crp_etype == EAGAIN) { + while ((error = crypto_invoke(crp)) == EAGAIN) { /* Reset the session ID */ if (tdb->tdb_cryptoid != 0) tdb->tdb_cryptoid = crp->crp_sid; - crypto_invoke(crp); } KERNEL_UNLOCK(); - if (crp->crp_etype) { - DPRINTF("crypto error %d", crp->crp_etype); + if (error) { + DPRINTF("crypto error %d", error); ipsecstat_inc(ipsec_noxform); - error = crp->crp_etype; goto drop; } @@ -1028,18 +1025,15 @@ esp_output(struct mbuf *m, struct tdb *tdb, int skip, int protoff) } KERNEL_LOCK(); - crypto_invoke(crp); - while (crp->crp_etype == EAGAIN) { + while ((error = crypto_invoke(crp)) == EAGAIN) { /* Reset the session ID */ if (tdb->tdb_cryptoid != 0) tdb->tdb_cryptoid = crp->crp_sid; - crypto_invoke(crp); } KERNEL_UNLOCK(); - if (crp->crp_etype) { - DPRINTF("crypto error %d", crp->crp_etype); + if (error) { + DPRINTF("crypto error %d", error); ipsecstat_inc(ipsec_noxform); - error = crp->crp_etype; goto drop; } diff --git a/sys/netinet/ip_ipcomp.c b/sys/netinet/ip_ipcomp.c index 59ac573b187..404ca8c170a 100644 --- a/sys/netinet/ip_ipcomp.c +++ b/sys/netinet/ip_ipcomp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipcomp.c,v 1.83 2021/10/24 14:24:29 bluhm Exp $ */ +/* $OpenBSD: ip_ipcomp.c,v 1.84 2021/10/24 14:50:42 tobhe Exp $ */ /* * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org) @@ -183,18 +183,15 @@ ipcomp_input(struct mbuf **mp, struct tdb *tdb, int skip, int protoff) tc->tc_dst = tdb->tdb_dst; KERNEL_LOCK(); - crypto_invoke(crp); - while (crp->crp_etype == EAGAIN) { + while ((error = crypto_invoke(crp)) == EAGAIN) { /* Reset the session ID */ if (tdb->tdb_cryptoid != 0) tdb->tdb_cryptoid = crp->crp_sid; - crypto_invoke(crp); } KERNEL_UNLOCK(); - if (crp->crp_etype) { - DPRINTF("crypto error %d", crp->crp_etype); + if (error) { + DPRINTF("crypto error %d", error); ipsecstat_inc(ipsec_noxform); - error = crp->crp_etype; goto drop; } @@ -501,21 +498,19 @@ ipcomp_output(struct mbuf *m, struct tdb *tdb, int skip, int protoff) crp->crp_sid = tdb->tdb_cryptoid; KERNEL_LOCK(); - crypto_invoke(crp); - while (crp->crp_etype == EAGAIN) { + while ((error = crypto_invoke(crp)) == EAGAIN) { /* Reset the session ID */ if (tdb->tdb_cryptoid != 0) tdb->tdb_cryptoid = crp->crp_sid; - crypto_invoke(crp); } KERNEL_UNLOCK(); - if (crp->crp_etype) { - DPRINTF("crypto error %d", crp->crp_etype); + if (error) { + DPRINTF("crypto error %d", error); ipsecstat_inc(ipsec_noxform); free(tc, M_XDATA, 0); m_freem(m); crypto_freereq(crp); - return crp->crp_etype; + return error; } ilen = crp->crp_ilen; -- 2.20.1