Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2dbafb45 authored by Manu Gautam's avatar Manu Gautam
Browse files

usb: host: replace %p with %pK



Format specifier %p can leak kernel addresses while not valuing the
kptr_restrict system settings. When kptr_restrict is set to (1), kernel
pointers printed using the %pK format specifier will be replaced with 0's.
Debugging Note : &pK prints only Zeros as address. If you need actual
address information, write 0 to kptr_restrict.

echo 0 > /proc/sys/kernel/kptr_restrict

CRs-fixed: 10528497
Change-Id: Icfe9a151e3cb186763541dc86cb5b67a7d739ece
Signed-off-by: default avatarManu Gautam <mgautam@codeaurora.org>
parent f33dab0c
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
static void __maybe_unused
dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
{
	ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
	ehci_dbg(ehci, "%s td %pK n%08x %08x t%08x p0=%08x\n", label, qtd,
		hc32_to_cpup(ehci, &qtd->hw_next),
		hc32_to_cpup(ehci, &qtd->hw_alt_next),
		hc32_to_cpup(ehci, &qtd->hw_token),
@@ -124,7 +124,7 @@ dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
{
	struct ehci_qh_hw *hw = qh->hw;

	ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
	ehci_dbg (ehci, "%s qh %pK n%08x info %x %x qtd %x\n", label,
		qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
	dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
}
@@ -132,7 +132,7 @@ dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
static void __maybe_unused
dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
{
	ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
	ehci_dbg (ehci, "%s [%d] itd %pK, next %08x, urb %pK\n",
		label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
		itd->urb);
	ehci_dbg (ehci,
@@ -163,7 +163,7 @@ dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
static void __maybe_unused
dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
{
	ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
	ehci_dbg (ehci, "%s [%d] sitd %pK, next %08x, urb %pK\n",
		label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
		sitd->urb);
	ehci_dbg (ehci,
@@ -436,7 +436,7 @@ static void qh_lines (
	scratch = hc32_to_cpup(ehci, &hw->hw_info1);
	hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
	temp = scnprintf (next, size,
			"qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
			"qh/%pK dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
			qh, scratch & 0x007f,
			speed_char (scratch),
			(scratch >> 8) & 0x000f,
@@ -464,7 +464,7 @@ static void qh_lines (
				mark = '/';
		}
		temp = snprintf (next, size,
				"\n\t%p%c%s len=%d %08x urb %p",
				"\n\t%pK%c%s len=%d %08x urb %pK",
				td, mark, ({ char *tmp;
				 switch ((scratch>>8)&0x03) {
				 case 0: tmp = "out"; break;
@@ -661,7 +661,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
			switch (hc32_to_cpu(ehci, tag)) {
			case Q_TYPE_QH:
				hw = p.qh->hw;
				temp = scnprintf (next, size, " qh%d-%04x/%p",
				temp = scnprintf (next, size, " qh%d-%04x/%pK",
						p.qh->ps.period,
						hc32_to_cpup(ehci,
							&hw->hw_info2)
@@ -723,20 +723,20 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
				break;
			case Q_TYPE_FSTN:
				temp = scnprintf (next, size,
					" fstn-%8x/%p", p.fstn->hw_prev,
					" fstn-%8x/%pK", p.fstn->hw_prev,
					p.fstn);
				tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
				p = p.fstn->fstn_next;
				break;
			case Q_TYPE_ITD:
				temp = scnprintf (next, size,
					" itd/%p", p.itd);
					" itd/%pK", p.itd);
				tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
				p = p.itd->itd_next;
				break;
			case Q_TYPE_SITD:
				temp = scnprintf (next, size,
					" sitd%d-%04x/%p",
					" sitd%d-%04x/%pK",
					p.sitd->stream->ps.period,
					hc32_to_cpup(ehci, &p.sitd->hw_uframe)
						& 0x0000ffff,
@@ -908,7 +908,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
	}

	if (!list_empty(&ehci->async_unlink)) {
		temp = scnprintf(next, size, "async unlink qh %p\n",
		temp = scnprintf(next, size, "async unlink qh %pK\n",
				list_first_entry(&ehci->async_unlink,
						struct ehci_qh, unlink_node));
		size -= temp;
+1 −1
Original line number Diff line number Diff line
@@ -1006,7 +1006,7 @@ idle_timeout:
		/* caller was supposed to have unlinked any requests;
		 * that's not our job.  just leak this memory.
		 */
		ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
		ehci_err (ehci, "qh %pK (#%02x) state %d%s\n",
			qh, ep->desc.bEndpointAddress, qh->qh_state,
			list_empty (&qh->qtd_list) ? "" : "(has tds)");
		break;
+7 −7
Original line number Diff line number Diff line
/* ehci-msm-hsic.c - HSUSB Host Controller Driver Implementation
 *
 * Copyright (c) 2011-2016, The Linux Foundation. All rights reserved.
 * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
 *
 * Partly derived from ehci-fsl.c and ehci-hcd.c
 * Copyright (c) 2000-2004 by David Brownell
@@ -271,7 +271,7 @@ static void dbg_log_event(struct urb *urb, char * event, unsigned extra)
		if (!str_to_event(event)) {
			write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
			scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx],
				DBG_MSG_LEN, "%s: [%s : %p]:[%s] "
				DBG_MSG_LEN, "%s: [%s : %pK]:[%s] "
				  "%02x %02x %04x %04x %04x  %u %d %s",
				  get_timestamp(tbuf), event, urb,
				  usb_urb_dir_in(urb) ? "in" : "out",
@@ -291,7 +291,7 @@ static void dbg_log_event(struct urb *urb, char * event, unsigned extra)
		} else {
			write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
			scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx],
				DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d %s",
				DBG_MSG_LEN, "%s: [%s : %pK]:[%s] %u %d %s",
				  get_timestamp(tbuf), event, urb,
				  usb_urb_dir_in(urb) ? "in" : "out",
				  urb->actual_length, extra,
@@ -304,7 +304,7 @@ static void dbg_log_event(struct urb *urb, char * event, unsigned extra)
	} else {
		write_lock_irqsave(&dbg_hsic_data.lck, flags);
		scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN,
			  "%s: [%s : %p]:ep%d[%s]  %u %d %s",
			  "%s: [%s : %pK]:ep%d[%s]  %u %d %s",
			  get_timestamp(tbuf), event, urb, ep_addr & 0x0f,
			  usb_urb_dir_in(urb) ? "in" : "out",
			  str_to_event(event) ? urb->actual_length :
@@ -336,7 +336,7 @@ static void dump_hsic_regs(struct usb_hcd *hcd)
		return;

	for (i = USB_REG_START_OFFSET; i <= USB_REG_END_OFFSET; i += 0x10)
		pr_info("%p: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i,
		pr_info("%pK: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i,
				readl_relaxed(hcd->regs + i),
				readl_relaxed(hcd->regs + i + 4),
				readl_relaxed(hcd->regs + i + 8),
@@ -690,7 +690,7 @@ static int msm_hsic_start(struct msm_hsic_hcd *mehci)
			while (seq[0] >= 0 && seq_count > 0) {
				val = readl_relaxed(mehci->tlmm_regs + seq[0]);
				val |= seq[1];
				dev_dbg(mehci->dev, "%s: writing %x to %p\n",
				dev_dbg(mehci->dev, "%s: writing %x to %pK\n",
						__func__,
						val, mehci->tlmm_regs + seq[0]);
				writel_relaxed(val, mehci->tlmm_regs + seq[0]);
@@ -1677,7 +1677,7 @@ static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id)
{
	struct msm_hsic_hcd *mehci = dev_id;

	pr_debug("%s: mehci:%p dev_id:%p\n", __func__, mehci, dev_id);
	pr_debug("%s: mehci:%pK dev_id:%pK\n", __func__, mehci, dev_id);

	if (mehci)
		msm_hsic_config_gpios(mehci, 0);
+4 −4
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status)

#ifdef EHCI_URB_TRACE
	ehci_dbg (ehci,
		"%s %s urb %p ep%d%s status %d len %d/%d\n",
		"%s %s urb %pK ep%d%s status %d len %d/%d\n",
		__func__, urb->dev->devpath, urb,
		usb_pipeendpoint (urb->pipe),
		usb_pipein (urb->pipe) ? "in" : "out",
@@ -350,7 +350,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
			/* Report Data Buffer Error: non-fatal but useful */
			if (token & QTD_STS_DBE)
				ehci_dbg(ehci,
					"detected DataBufferErr for urb %p ep%d%s len %d, qtd %p [qh %p]\n",
					"detected DataBufferErr for urb %pK ep%d%s len %d, qtd %pK [qh %pK]\n",
					urb,
					usb_endpoint_num(&urb->ep->desc),
					usb_endpoint_dir_in(&urb->ep->desc) ? "in" : "out",
@@ -924,7 +924,7 @@ qh_make (
		}
		break;
	default:
		ehci_dbg(ehci, "bogus dev %p speed %d\n", urb->dev,
		ehci_dbg(ehci, "bogus dev %pK speed %d\n", urb->dev,
			urb->dev->speed);
done:
		qh_destroy(ehci, qh);
@@ -1112,7 +1112,7 @@ submit_async (
		struct ehci_qtd *qtd;
		qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list);
		ehci_dbg(ehci,
			 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
			 "%s %s urb %pK ep%d%s len %d, qtd %pK [qh %pK]\n",
			 __func__, urb->dev->devpath, urb,
			 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
			 urb->transfer_buffer_length,
+11 −11
Original line number Diff line number Diff line
@@ -548,7 +548,7 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
	unsigned	period = qh->ps.period;

	dev_dbg(&qh->ps.udev->dev,
		"link qh%d-%04x/%p start %d [%d/%d us]\n",
		"link qh%d-%04x/%pK start %d [%d/%d us]\n",
		period, hc32_to_cpup(ehci, &qh->hw->hw_info2)
			& (QH_CMASK | QH_SMASK),
		qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs);
@@ -641,7 +641,7 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
		: (qh->ps.usecs * 8);

	dev_dbg(&qh->ps.udev->dev,
		"unlink qh%d-%04x/%p start %d [%d/%d us]\n",
		"unlink qh%d-%04x/%pK start %d [%d/%d us]\n",
		qh->ps.period,
		hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK),
		qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs);
@@ -751,7 +751,7 @@ static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
		 * FIXME kill the now-dysfunctional queued urbs
		 */
		else {
			ehci_err(ehci, "can't reschedule qh %p, err %d\n",
			ehci_err(ehci, "can't reschedule qh %pK, err %d\n",
					qh, rc);
		}
	}
@@ -869,7 +869,7 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)

	/* reuse the previous schedule slots, if we can */
	if (qh->ps.phase != NO_FRAME) {
		ehci_dbg(ehci, "reused qh %p schedule\n", qh);
		ehci_dbg(ehci, "reused qh %pK schedule\n", qh);
		return 0;
	}

@@ -1552,7 +1552,7 @@ iso_stream_schedule (

			/* no room in the schedule */
			if (!done) {
				ehci_dbg(ehci, "iso sched full %p", urb);
				ehci_dbg(ehci, "iso sched full %pK", urb);
				status = -ENOSPC;
				goto fail;
			}
@@ -1606,7 +1606,7 @@ iso_stream_schedule (

	/* Is the schedule already full? */
	if (unlikely(!empty && start < period)) {
		ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n",
		ehci_dbg(ehci, "iso sched full %pK (%u-%u < %u mod %u)\n",
				urb, stream->next_uframe, base, period, mod);
		status = -ENOSPC;
		goto fail;
@@ -1635,7 +1635,7 @@ iso_stream_schedule (
	/* How many uframes and packets do we need to skip? */
	skip = (now2 - start + period - 1) & -period;
	if (skip >= span) {		/* Entirely in the past? */
		ehci_dbg(ehci, "iso underrun %p (%u+%u < %u) [%u]\n",
		ehci_dbg(ehci, "iso underrun %pK (%u+%u < %u) [%u]\n",
				urb, start + base, span - period, now2 + base,
				base);

@@ -1662,7 +1662,7 @@ iso_stream_schedule (
 use_start:
	/* Tried to schedule too far into the future? */
	if (unlikely(start + span - period >= mod + wrap)) {
		ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n",
		ehci_dbg(ehci, "request %pK would overflow (%u+%u >= %u)\n",
				urb, start, span - period, mod + wrap);
		status = -EFBIG;
		goto fail;
@@ -1957,7 +1957,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,

#ifdef EHCI_URB_TRACE
	ehci_dbg (ehci,
		"%s %s urb %p ep%d%s len %d, %d pkts %d uframes [%p]\n",
		"%s %s urb %pK ep%d%s len %d, %d pkts %d uframes [%pK]\n",
		__func__, urb->dev->devpath, urb,
		usb_pipeendpoint (urb->pipe),
		usb_pipein (urb->pipe) ? "in" : "out",
@@ -2337,7 +2337,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,

#ifdef EHCI_URB_TRACE
	ehci_dbg (ehci,
		"submit %p dev%s ep%d%s-iso len %d\n",
		"submit %pK dev%s ep%d%s-iso len %d\n",
		urb, urb->dev->devpath,
		usb_pipeendpoint (urb->pipe),
		usb_pipein (urb->pipe) ? "in" : "out",
@@ -2490,7 +2490,7 @@ restart:
				q = *q_p;
				break;
			default:
				ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
				ehci_dbg(ehci, "corrupt type %d frame %d shadow %pK\n",
					type, frame, q.ptr);
				// BUG ();
				/* FALL THROUGH */
Loading