-/* $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)
*
/*
* Dispatch a crypto request to the appropriate crypto devices.
*/
-void
+int
crypto_invoke(struct cryptop *crp)
{
u_int64_t nid;
s = splvm();
if (crp->crp_ndesc < 1 || crypto_drivers == NULL) {
- crp->crp_etype = EINVAL;
+ error = EINVAL;
goto done;
}
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);
}
splx(s);
- return;
+ return error;
migrate:
/* Migrate session. */
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;
}
/*
-/* $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)
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 */
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 *);
-/* $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 <marco@peereboom.us>
* Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org>
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);
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);
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
return (0);
bad:
- /* wu is unwound by sr_wu_put */
- if (crwu)
- crwu->cr_crp->crp_etype = EINVAL;
- return (1);
+ return (EINVAL);
}
void
{
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 */
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;
}
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)
{
-/* $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 <marco@peereboom.us>
* Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org>
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);
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
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);
!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);
-/* $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
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;
}
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;
}
-/* $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
}
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;
}
}
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;
}
-/* $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)
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;
}
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;