Skip to content

Commit 0fdcc88

Browse files
hfreudeAlexander Gordeev
authored andcommitted
s390/zcrypt: cleanup some debug code
This patch removes most of the debug code which is build in when CONFIG_ZCRYPT_DEBUG is enabled. There is no real exploiter for this code any more and at least one ioctl fails with this code enabled. The CONFIG_ZCRYPT_DEBUG kernel config option still makes sense as some debug sysfs entries can get enabled with this and maybe long term a new better designed debug and error injection way will get introduced. This patch only removes code surrounded by the named kernel config option. This option should by default always be off anyway. The structs and defines removed by the patch have been used only by code surrounded by a CONFIG_ZCRYPT_DEBUG ifdef and thus can be removed also. In the end this patch removes all the failure-injection possibilities which had been available when the kernel had been build with CONFIG_ZCRYPT_DEBUG. It has never been used that much and was too unflexible anyway. Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent edbe289 commit 0fdcc88

6 files changed

Lines changed: 0 additions & 140 deletions

File tree

drivers/s390/crypto/ap_bus.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -233,38 +233,13 @@ struct ap_queue {
233233

234234
typedef enum ap_sm_wait (ap_func_t)(struct ap_queue *queue);
235235

236-
/* failure injection cmd struct */
237-
struct ap_fi {
238-
union {
239-
u16 cmd; /* fi flags + action */
240-
struct {
241-
u8 flags; /* fi flags only */
242-
u8 action; /* fi action only */
243-
};
244-
};
245-
};
246-
247-
/* all currently known fi actions */
248-
enum ap_fi_actions {
249-
AP_FI_ACTION_CCA_AGENT_FF = 0x01,
250-
AP_FI_ACTION_CCA_DOM_INVAL = 0x02,
251-
AP_FI_ACTION_NQAP_QID_INVAL = 0x03,
252-
};
253-
254-
/* all currently known fi flags */
255-
enum ap_fi_flags {
256-
AP_FI_FLAG_NO_RETRY = 0x01,
257-
AP_FI_FLAG_TOGGLE_SPECIAL = 0x02,
258-
};
259-
260236
struct ap_message {
261237
struct list_head list; /* Request queueing. */
262238
unsigned long psmid; /* Message id. */
263239
void *msg; /* Pointer to message buffer. */
264240
size_t len; /* actual msg len in msg buffer */
265241
size_t bufsize; /* allocated msg buffer size */
266242
u16 flags; /* Flags, see AP_MSG_FLAG_xxx */
267-
struct ap_fi fi; /* Failure Injection cmd */
268243
int rc; /* Return code for this message */
269244
void *private; /* ap driver private pointer. */
270245
/* receive is called from tasklet context */

drivers/s390/crypto/ap_queue.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,6 @@ static enum ap_sm_wait ap_sm_write(struct ap_queue *aq)
274274

275275
/* Start the next request on the queue. */
276276
ap_msg = list_entry(aq->requestq.next, struct ap_message, list);
277-
#ifdef CONFIG_ZCRYPT_DEBUG
278-
if (ap_msg->fi.action == AP_FI_ACTION_NQAP_QID_INVAL) {
279-
AP_DBF_WARN("%s fi cmd 0x%04x: forcing invalid qid 0xFF00\n",
280-
__func__, ap_msg->fi.cmd);
281-
qid = 0xFF00;
282-
}
283-
#endif
284277
status = __ap_send(qid, ap_msg->psmid,
285278
ap_msg->msg, ap_msg->len,
286279
ap_msg->flags & AP_MSG_FLAG_SPECIAL);

drivers/s390/crypto/zcrypt_api.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,6 @@ static long zcrypt_rsa_modexpo(struct ap_perms *perms,
661661

662662
ap_init_message(&ap_msg);
663663

664-
#ifdef CONFIG_ZCRYPT_DEBUG
665-
if (tr && tr->fi.cmd)
666-
ap_msg.fi.cmd = tr->fi.cmd;
667-
#endif
668-
669664
if (mex->outputdatalength < mex->inputdatalength) {
670665
func_code = 0;
671666
rc = -EINVAL;
@@ -771,11 +766,6 @@ static long zcrypt_rsa_crt(struct ap_perms *perms,
771766

772767
ap_init_message(&ap_msg);
773768

774-
#ifdef CONFIG_ZCRYPT_DEBUG
775-
if (tr && tr->fi.cmd)
776-
ap_msg.fi.cmd = tr->fi.cmd;
777-
#endif
778-
779769
if (crt->outputdatalength < crt->inputdatalength) {
780770
func_code = 0;
781771
rc = -EINVAL;
@@ -883,16 +873,6 @@ static long _zcrypt_send_cprb(bool userspace, struct ap_perms *perms,
883873
xcrb->status = 0;
884874
ap_init_message(&ap_msg);
885875

886-
#ifdef CONFIG_ZCRYPT_DEBUG
887-
if (tr && tr->fi.cmd)
888-
ap_msg.fi.cmd = tr->fi.cmd;
889-
if (tr && tr->fi.action == AP_FI_ACTION_CCA_AGENT_FF) {
890-
ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid agent_ID 'FF'\n",
891-
__func__, tr->fi.cmd);
892-
xcrb->agent_ID = 0x4646;
893-
}
894-
#endif
895-
896876
rc = prep_cca_ap_msg(userspace, xcrb, &ap_msg, &func_code, &domain);
897877
if (rc)
898878
goto out;
@@ -982,14 +962,6 @@ static long _zcrypt_send_cprb(bool userspace, struct ap_perms *perms,
982962
if (*domain == AUTOSEL_DOM)
983963
*domain = AP_QID_QUEUE(qid);
984964

985-
#ifdef CONFIG_ZCRYPT_DEBUG
986-
if (tr && tr->fi.action == AP_FI_ACTION_CCA_DOM_INVAL) {
987-
ZCRYPT_DBF_WARN("%s fi cmd 0x%04x: forcing invalid domain\n",
988-
__func__, tr->fi.cmd);
989-
*domain = 99;
990-
}
991-
#endif
992-
993965
rc = pref_zq->ops->send_cprb(userspace, pref_zq, xcrb, &ap_msg);
994966

995967
spin_lock(&zcrypt_list_lock);
@@ -1058,11 +1030,6 @@ static long _zcrypt_send_ep11_cprb(bool userspace, struct ap_perms *perms,
10581030

10591031
ap_init_message(&ap_msg);
10601032

1061-
#ifdef CONFIG_ZCRYPT_DEBUG
1062-
if (tr && tr->fi.cmd)
1063-
ap_msg.fi.cmd = tr->fi.cmd;
1064-
#endif
1065-
10661033
target_num = (unsigned short)xcrb->targets_num;
10671034

10681035
/* empty list indicates autoselect (all available targets) */
@@ -1473,23 +1440,10 @@ static int icarsamodexpo_ioctl(struct ap_perms *perms, unsigned long arg)
14731440
if (copy_from_user(&mex, umex, sizeof(mex)))
14741441
return -EFAULT;
14751442

1476-
#ifdef CONFIG_ZCRYPT_DEBUG
1477-
if (mex.inputdatalength & (1U << 31)) {
1478-
if (!capable(CAP_SYS_ADMIN))
1479-
return -EPERM;
1480-
tr.fi.cmd = (u16)(mex.inputdatalength >> 16);
1481-
}
1482-
mex.inputdatalength &= 0x0000FFFF;
1483-
#endif
1484-
14851443
do {
14861444
rc = zcrypt_rsa_modexpo(perms, &tr, &mex);
14871445
if (rc == -EAGAIN)
14881446
tr.again_counter++;
1489-
#ifdef CONFIG_ZCRYPT_DEBUG
1490-
if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1491-
break;
1492-
#endif
14931447
} while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
14941448
/* on failure: retry once again after a requested rescan */
14951449
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
@@ -1518,23 +1472,10 @@ static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg)
15181472
if (copy_from_user(&crt, ucrt, sizeof(crt)))
15191473
return -EFAULT;
15201474

1521-
#ifdef CONFIG_ZCRYPT_DEBUG
1522-
if (crt.inputdatalength & (1U << 31)) {
1523-
if (!capable(CAP_SYS_ADMIN))
1524-
return -EPERM;
1525-
tr.fi.cmd = (u16)(crt.inputdatalength >> 16);
1526-
}
1527-
crt.inputdatalength &= 0x0000FFFF;
1528-
#endif
1529-
15301475
do {
15311476
rc = zcrypt_rsa_crt(perms, &tr, &crt);
15321477
if (rc == -EAGAIN)
15331478
tr.again_counter++;
1534-
#ifdef CONFIG_ZCRYPT_DEBUG
1535-
if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1536-
break;
1537-
#endif
15381479
} while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
15391480
/* on failure: retry once again after a requested rescan */
15401481
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
@@ -1563,23 +1504,10 @@ static int zsecsendcprb_ioctl(struct ap_perms *perms, unsigned long arg)
15631504
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
15641505
return -EFAULT;
15651506

1566-
#ifdef CONFIG_ZCRYPT_DEBUG
1567-
if ((xcrb.status & 0x8000FFFF) == 0x80004649 /* 'FI' */) {
1568-
if (!capable(CAP_SYS_ADMIN))
1569-
return -EPERM;
1570-
tr.fi.cmd = (u16)(xcrb.status >> 16);
1571-
}
1572-
xcrb.status = 0;
1573-
#endif
1574-
15751507
do {
15761508
rc = _zcrypt_send_cprb(true, perms, &tr, &xcrb);
15771509
if (rc == -EAGAIN)
15781510
tr.again_counter++;
1579-
#ifdef CONFIG_ZCRYPT_DEBUG
1580-
if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1581-
break;
1582-
#endif
15831511
} while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
15841512
/* on failure: retry once again after a requested rescan */
15851513
if ((rc == -ENODEV) && (zcrypt_process_rescan()))
@@ -1609,23 +1537,10 @@ static int zsendep11cprb_ioctl(struct ap_perms *perms, unsigned long arg)
16091537
if (copy_from_user(&xcrb, uxcrb, sizeof(xcrb)))
16101538
return -EFAULT;
16111539

1612-
#ifdef CONFIG_ZCRYPT_DEBUG
1613-
if (xcrb.req_len & (1ULL << 63)) {
1614-
if (!capable(CAP_SYS_ADMIN))
1615-
return -EPERM;
1616-
tr.fi.cmd = (u16)(xcrb.req_len >> 48);
1617-
}
1618-
xcrb.req_len &= 0x0000FFFFFFFFFFFFULL;
1619-
#endif
1620-
16211540
do {
16221541
rc = _zcrypt_send_ep11_cprb(true, perms, &tr, &xcrb);
16231542
if (rc == -EAGAIN)
16241543
tr.again_counter++;
1625-
#ifdef CONFIG_ZCRYPT_DEBUG
1626-
if (rc == -EAGAIN && (tr.fi.flags & AP_FI_FLAG_NO_RETRY))
1627-
break;
1628-
#endif
16291544
} while (rc == -EAGAIN && tr.again_counter < TRACK_AGAIN_MAX);
16301545
/* on failure: retry once again after a requested rescan */
16311546
if ((rc == -ENODEV) && (zcrypt_process_rescan()))

drivers/s390/crypto/zcrypt_api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ struct zcrypt_track {
6060
int again_counter; /* retry attempts counter */
6161
int last_qid; /* last qid used */
6262
int last_rc; /* last return code */
63-
#ifdef CONFIG_ZCRYPT_DEBUG
64-
struct ap_fi fi; /* failure injection cmd */
65-
#endif
6663
};
6764

6865
/* defines related to message tracking */

drivers/s390/crypto/zcrypt_msgtype50.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ static int ICAMEX_msg_to_type50MEX_msg(struct zcrypt_queue *zq,
246246
copy_from_user(inp, mex->inputdata, mod_len))
247247
return -EFAULT;
248248

249-
#ifdef CONFIG_ZCRYPT_DEBUG
250-
if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL)
251-
ap_msg->flags ^= AP_MSG_FLAG_SPECIAL;
252-
#endif
253-
254249
return 0;
255250
}
256251

@@ -338,11 +333,6 @@ static int ICACRT_msg_to_type50CRT_msg(struct zcrypt_queue *zq,
338333
copy_from_user(inp, crt->inputdata, mod_len))
339334
return -EFAULT;
340335

341-
#ifdef CONFIG_ZCRYPT_DEBUG
342-
if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL)
343-
ap_msg->flags ^= AP_MSG_FLAG_SPECIAL;
344-
#endif
345-
346336
return 0;
347337
}
348338

drivers/s390/crypto/zcrypt_msgtype6.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,6 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
425425
memcmp(function_code, "AU", 2) == 0)
426426
ap_msg->flags |= AP_MSG_FLAG_SPECIAL;
427427

428-
#ifdef CONFIG_ZCRYPT_DEBUG
429-
if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL)
430-
ap_msg->flags ^= AP_MSG_FLAG_SPECIAL;
431-
#endif
432-
433428
/* check CPRB minor version, set info bits in ap_message flag field */
434429
switch (*(unsigned short *)(&msg->cprbx.func_id[0])) {
435430
case 0x5432: /* "T2" */
@@ -535,11 +530,6 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
535530
if (msg->cprbx.flags & 0x20)
536531
ap_msg->flags |= AP_MSG_FLAG_SPECIAL;
537532

538-
#ifdef CONFIG_ZCRYPT_DEBUG
539-
if (ap_msg->fi.flags & AP_FI_FLAG_TOGGLE_SPECIAL)
540-
ap_msg->flags ^= AP_MSG_FLAG_SPECIAL;
541-
#endif
542-
543533
/* set info bits in ap_message flag field */
544534
if (msg->cprbx.flags & 0x80)
545535
ap_msg->flags |= AP_MSG_FLAG_ADMIN;

0 commit comments

Comments
 (0)