Send-Document has no job-state check, resurrects canceled jobs and re-prints processing jobs

Abierto Apto para principiantes
#1,833 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
backend, security

Línea de trabajo

Empieza en scheduler/ipp.c en send_document(), donde primero se hacen la búsqueda del trabajo y la comprobación de propiedad, y lee el bloque de gestión de estados alrededor de las líneas 10273-10295 antes de la llamada a add_file() cerca de la línea 10224. Reproduce la secuencia de cuatro pasos del issue con ipptool usando una impresora raw test en el puerto 8631. Se considera terminado cuando un Send-Document a un trabajo cancelado, completado o abortado se rechaza con un error y el trabajo permanece en su estado terminal, y el comportamiento existente de stopped y held sigue pasando las pruebas del scheduler.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

send_document() never checks whether the target job is in a terminal state. A user who owns a job can send a document to a job that has already been canceled, completed, or aborted. CUPS accepts the document, sets the job back to PENDING or HELD, and starts it. A canceled job can therefore be revived with Release-Job; a job that is already being processed can be dragged back to HELD and printed a second time when the hold expires.

Details

scheduler/ipp.c, send_document():

  • The job is looked up (scheduler/ipp.c:10016) and ownership is validated (scheduler/ipp.c:10032).
  • The document is added to the job with add_file() at scheduler/ipp.c:10224, unconditionally.
  • The only state transitions handled are IPP_JOB_STOPPED and IPP_JOB_HELD (scheduler/ipp.c:10273-10295). IPP_JOB_CANCELED, IPP_JOB_ABORTED and IPP_JOB_COMPLETED are not handled; no error is returned.
  • On the last document the function sets start_job = 1 (scheduler/ipp.c:10300) and calls cupsdCheckJobs() (scheduler/ipp.c:10341-10342), which starts the job.
  • On a non-last document it sets job->state = IPP_JOB_HELD, job->hold_until = time(NULL) + MultipleOperationTimeout (scheduler/ipp.c:10310-10312).

The same code is present in CUPS 2.4.20. send_document() needs a check equivalent to if (job->state_value >= IPP_JOB_CANCELED) return IPP_NOT_POSSIBLE; before adding the file.

PoC

Configuration as in the standard cupsd test setup: Listen 127.0.0.1:8631, <Location /> Allow localhost </Location>, one raw printer test.

Sequence and observed wire results:

1. Create-Job (printer-uri=ipp://127.0.0.1:8631/printers/test)
   -> successful-ok, job-id=1, job-state=3 (pending)

2. Send-Document (job-id=1, last-document=true, document=raw bytes)
   -> successful-ok, job-state=5 (processing) then 9 (completed)

3. Cancel-Job (job-id=1)
   -> successful-ok, job-state=7 (canceled)

4. Send-Document (job-id=1, last-document=true, document=raw bytes)
   -> successful-ok

Step 4 is the defect: CUPS accepts a document for a job in state 7 and changes its state. With last-document=false it sets the job to HELD (4); a following Release-Job returns successful-ok and the job returns to PROCESSING (6) and prints again.

Same result when the document is sent while the job is already processing:

1. Print-Job (raw document)
   -> job-state=5 (processing)
2. Send-Document (job-id=1, last-document=false)
   -> successful-ok, job-state=4 (held)
3. Release-Job (job-id=1)
   -> successful-ok, job-state=6 (processing)

Request shape for step 4 (ipptool):

{
  OPERATION Send-Document
  GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri job-uri ipp://127.0.0.1:8631/jobs/1
  ATTR name requesting-user-name attacker
  ATTR mimeMediaType document-format application/vnd.cups-raw
  ATTR boolean last-document false
  FILE /tmp/poc.txt
}
Lenguaje dominante
C
Estrellas
1.8k
Forks
367
Merge medio
1 d 16 h
PR fusionados (30 d)
7

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenPrinting/cups

Todos los issues de OpenPrinting/cups

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.